在获得一个
ServiceConnection
实例时需要覆写onServiceConnected
和onServiceDisconnected
两个方法,一直疑惑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
方法