有人会在些bound service的client的时候会利用onServiceDisconnected来释放资源,但是并达不到预期效果。在呼叫unbindService后onServiceDisconnected并没有被呼叫。
请仔细阅读文档
public abstract void onServiceDisconnected (ComponentName name)
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来测试。