简体   繁体   English

如何强制android服务被销毁?

[英]How to force android service to be destroyed?

I execute stopSelf as service finishes working (from within service) but it is not destroyed (see using log output in onDestroy() ) right after it. 我在服务完成工作时(从服务内部)执行stopSelf ,但是它并没有被破坏(请参阅在onDestroy()使用日志输出)。 It leads that startService uses existing (stopped) service instead of starting new one. 它导致startService使用现有(已停止)服务而不是启动新服务。 How can i force service to be destroyed right after it is stopped? 服务停止后如何立即将其销毁?

From Documentation: 从文档:

A service can be both started and have connections bound to it. 服务既可以启动,也可以绑定连接。 In such a case, the system will keep the service running as long as either it is started or there are one or more connections to it with the Context.BIND_AUTO_CREATE flag. 在这种情况下,只要服务启动,或者使用Context.BIND_AUTO_CREATE标志与该服务建立一个或多个连接,系统就会保持该服务运行。 Once neither of these situations hold, the service's onDestroy () method is called and the service is effectively terminated. 一旦这两种情况都不成立, 就将调用服务的onDestroy ()方法,并有效终止该服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM