服务被取消绑定后销毁 [英] Service gets destroyed after unbinding

查看:151
本文介绍了服务被取消绑定后销毁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回START_STICKY onStartCommand,由startService启动的应用程序的onCreate服务,在我的活动我绑定到该服务可以互换,但由于某些原因的服务获取每次销毁了所有我的活动取消绑定,但我可以gaurantee stopSelf \\ stopService从未被调用。可能是什么原因?

i have a service that returns START_STICKY onStartCommand, and is started by startService on the Application's onCreate, in my activities i bind to this service interchangeably, but for some reason the Service gets destroyed everytime all my activities unbind to it, but i can gaurantee stopSelf\stopService was never called. what could be the reason?

推荐答案

好吧,找到了答案 - 对应用程序的onCreate到startService呼叫DONT继电器,因为在我的情况下,我叫stopService只有当我的主要活动是由用户exitted回到preSS,但即使有运行我的应用程序的Andr​​oid没有杀过程中没有活动,也没有服务,并没有发布垃圾收集Application对象,这导致下一次用户推出我的应用程序,应用程序的onCreate是得不到称为它已经存在,因此该服务的生命周期被绑定到它尝试各种活动才处理的,这就是为什么当中的所有活动无限它得到销毁。

Ok, found the answer - DONT relay on a call to startService on Application's onCreate, because in my case i called stopService only when my main activity was exitted by user back press, but even though there were no activities nor services running for my application android did not kill the process and did not release the Application object for garbage collecting, this caused that the next time user launched my app, Application's onCreate was NOT getting called as it already existed, therefore the service's lifetime was handled only by the activites binded to it and this is why it got destroyed when all activites unbounded.

ehhhh Android和他们的怪异设计...

ehhhh Android and their weird design...

这篇关于服务被取消绑定后销毁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆