In my android application by swiping it to left/right will kill application.Is there a way to recognize that user requested to kill my application from whatever the activity user requests? for activity it is onDestroy() and for application is there anything to recognize??
-
2Look an exaustive response here: http://stackoverflow.com/questions/14479979/action-on-application-killed-in-android – Seraphim's Feb 14 '14 at 11:52
-
Why do you need to know when your app is closed? – Seraphim's Feb 14 '14 at 11:53
-
i want to stop my services when my app is being killed from whatever may be the activity – praveen Feb 14 '14 at 12:00
-
1@praveen if I understood your intentions correctly, you can stop your services if no Activities are open. To do this, monitor onStart and onStop count of all your activities. If all of them are stopped - stop your services. – Yaroslav Mytkalyk Feb 14 '14 at 12:34
-
@Doctoror Drive I do something similar... – Seraphim's Feb 14 '14 at 12:58
-
1@DoctororDrive by doing swipe left/right if we kill application **onTaskRemoved** method of each Service of that application will be called from there i'm stopping Services – praveen Sep 08 '14 at 09:50
1 Answers
Your question relates most to this:
Is quitting an application frowned upon?
Your activities can stop your service like this:
Android stop service when exit the app
If you cannot manage an easier way through Activities to determine if you service should stop processing (a "running" service that does nothing is not a big deal, right?) then you can use inactivity as a measure of when to stop processing within your service:
How to detect USER INACTIVITY in android
In other words, because Android lifecycles are different from desktop (as they should be - rarely does someone "take a call" on a desktop and then have to return to their previous work - you need to manage the interaction with the app differently than you would a desktop. Apps can't "die" just because they are not visible on the screen for a little while.