How can start Service several times while Service is alive

本秂侑毒 提交于 2019-12-24 20:19:36

问题


I want to do this acts with my Service :

1)start App

3)start a Service by App

4)update my UI by Service

5)close App but the Service keep work

6)sart App again

7)connect to Service (not run new Service)

I want in my service public variable during living Service do not change.


回答1:


If you return START_STICKY from onStartCommand() then your Service will run unstil it is explicitly stopped. You can then decide how you want to stop your Service, either by something calling stopService() or by the Service calling stopSelf() when it no longer wants to run.

Please also note that Android can kill your Service pretty much whenever it wants to. If you have returned START_STICKY then Android will restart your Service after it kills it, but there is nothing you can do to ensure that Android will not kill your Service.



来源:https://stackoverflow.com/questions/55710144/how-can-start-service-several-times-while-service-is-alive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!