Skip to content Skip to sidebar Skip to footer

How Can Start Service Several Times While Service Is Alive

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

Solution 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.

Post a Comment for "How Can Start Service Several Times While Service Is Alive"