问题描述
有两个应用A和B,通过aidl来来共享服务,现在有个问题:当我想把服务Destroy的时候,为什么要A和B都unbind后,才会Destroy;为什么不是谁create的,就由谁Destroy??????你们能看懂我说的吗?????
解决方案
官方文档上写的很清楚,即便你调用了stopService,但系统只会在当前服务的请求者全部unbind后,才会真正停止这个Service。public abstract boolean stopService (Intent service)Since: API Level 1Request that a given application service be stopped. If the service is not running, nothing happens. Otherwise it is stopped. Note that calls to startService() are not counted -- this stops the service no matter how many times it was started.Note that if a stopped service still has ServiceConnection objects bound to it with the BIND_AUTO_CREATE set, it will not be destroyed until all of these bindings are removed. See the Service documentation for more details on a service's lifecycle.
解决方案二:
你多次绑定一个服务的时候,service的onCreate()方法只调用一次。