我的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来测试。

发布了24 篇原创文章 · 获赞 6 · 访问量 8万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览