我的onServiceDisconnected为什么没有被呼叫


有人会在些bound service的client的时候会利用onServiceDisconnected来释放资源,但是并达不到预期效果。在呼叫unbindService后onServiceDisconnected并没有被呼叫。

请仔细阅读文档


public abstract void onServiceDisconnected (ComponentName name)
Added in  API level 1

Called when a connection to the Service has been lost. This typically happens when the process hosting the service has crashed or been killed. This does not remove the ServiceConnection itself -- this binding to the service will remain active, and you will receive a call to onServiceConnected(ComponentName, IBinder) when the Service is next running.

Parameters
name The concrete component name of the service whose connection has been lost.

尤其是This typically happens when the process hosting the service has crashed or been killed. 

即当service所在进程crash或者被kill的时候,onServiceDisconnected才会被呼叫。

如果要严重的话,请使用adb shell kill pid 命令kill service来测试。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值