在获得一个
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方法
当主动停止Android Service时,onServiceDisconnected方法通常不会被调用,除非服务所在的进程崩溃或被杀死。此时,ServiceConnection保持活跃,并在Service下次运行时重新调用onServiceConnected。
1万+

被折叠的 条评论
为什么被折叠?



