关于onServiceDisconnected不会被调用的问题

在获得一个ServiceConnection实例时需要覆写onServiceConnectedonServiceDisconnected两个方法,一直疑惑onServiceDisConnected方法为什么在主动unbindService后不会调用,查了官方文档后有初步的了解

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. 原文 Android Developer

大概的意思是onServiceDisconnected只会在Service丢失时才会调用, 通常会在Service所在进程被迫终止时才会调用, 当Service重新运行时会再次调用onServiceConnected方法

你可能感兴趣的:(关于onServiceDisconnected不会被调用的问题)