我对Service Lifecycle的理解

[size=large]本文部分来自android->developer->dev guide->Application Fundamentals[/size]

[list]
[*][b]摘自Class Overview[/b]
[/list]
A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use. Each service class must have a corresponding <service> declaration in its package's AndroidManifest.xml. Services can be started with Context.startService() and Context.bindService().

[list]
[*][b]两种启动service的方法:[/b]
[/list]
Using a service in two ways
Context.startService() and Context.bindService(),这两种方法实现不同的接口。
startService()生命周期调用的方法
void onCreate()
void onStart(Intent intent)
void onDestroy()
bindService()生命周期调用的方法
void onCreate()
IBinder onBind(Intent intent)
boolean onUnbind(Intent intent)
void onRebind(Intent intent)
void onDestroy()


[list]
[*][b]two nested loops of the service's lifecycle[/b]
[/list]
By implementing these methods, you can monitor two nested loops of the service's lifecycle:
* The entire lifetime of a service happens between the time onCreate() is called and the time onDestroy() returns. Like an activity, a service does its initial setup in onCreate(), and releases all remaining resources in onDestroy(). For example, a music playback service could create the thread where the music will be played in onCreate(), and then stop the thread in onDestroy().
* The active lifetime of a service begins with a call to onStart(). This method is handed the Intent object that was passed to startService(). The music service would open the Intent to discover which music to play, and begin the playback.
There's no equivalent callback for when the service stops — no onStop() method.

[list]
[*][b]diagram illustrates[/b]
[/list]

[img]http://dl.iteye.com/upload/attachment/394249/7ae0fc42-b17f-3f0c-8347-c0bd55bdccc3.png[/img]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值