How to stop an Android Service ONLY when there are no other activities in my app running?
Posted
by johnrock
on Stack Overflow
See other posts from Stack Overflow
or by johnrock
Published on 2010-03-13T23:43:28Z
Indexed on
2010/03/13
23:45 UTC
Read the original article
Hit count: 278
android
|android-service
Is there a way I can test if there are any other activities in my app still alive? I am looking to stop a service in an onDestroy method, but only want to do this if there are no other activities from my app still alive on the stack.
I have the call stop the service in the main activity's onDestroy() method. This works perfect EXCEPT that if a user launches my app, then launches a few activities in my app, then hits the home screen and RELAUNCHES my app, they will subvert my order and the main activity will now be above other activities of my app. From this state, if they hit the back button and 'back out' of my home screen they will trigger the onDestroy() method and kill the service even though there are other activities open on the stack. I want to avoid this by stopping the service ONLY if I am sure there are no other activities of mine open on the stack. Possible?
© Stack Overflow or respective owner