Stop a service when none of the activities are in the foreground?

See the lifecycle of Activity given at developer.android.com/reference/android/... Understand when the methods onStart, onStop and onPause gets invoked. You can then startService/stopService from within them accordingly.

I already know how they work, I just want to know when none of my activities are in the foreground and then be able to do something according to it. – biquillo Mar 9 at 21:19 So, you do know that onPause() gets called when some other activity comes in front of your activity and onStop() gets called when your activity is no longer visible, right? – Vino Mar 10 at 13:10 sure, the problem is how my app knows that none of my activities are in the foreground – biquillo Mar 10 at 22:56.

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.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions