service生命周期

startService和bindService启动:
当service还没启动时,都会调用onCreate方法,如果已经启动了,将不会 调用onCreate

startService调用多次,会调用多次onStartCommad
binService调用多次,会调用bindService多次(指不同的连接)。

由service又被StartService调用过的,service会一直在后台,必须显示的调用stopService才能停止service或者service本身调用stopService。
stopService有个方法是stopService(int startdID)执行的时会将startID会和最新的id对比,如果不相等的话就不会停止服务,防止停止服务的时候又有请求。

当只由bindService启动的app,都所有客户端都调用过unbind之后,系统会调用onDestroy,杀死Service。

如果onBinder返回为空,则serviceConnected不会调用。
Additionally, if your service is started and accepts binding, then when the system calls your onUnbind() method, you can optionally return true if you would like to receive a call to onRebind() the next time a client binds to the service. onRebind() returns void, but the client still receives the IBinder in its onServiceConnected() callback. The following figure illustrates the logic for this kind of lifecycle.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值