Posted By: Anonymous
I want to close my application, so that it no longer runs in the background.
How to do that? Is this good practice on Android platform?
If I rely on the “back” button, it closes the app, but it stays in background. There is even application called “TaskKiller” just to kill those apps in the background.
Just to answer my own question now after so much time (since CommonsWare commented on the most popular answer telling we should NOT do this):
When I want to quit the app:
- I start my first activity (either splash screen, or whatever activity is currently at the bottom of the activity stack) with
FLAG_ACTIVITY_CLEAR_TOP(which will quit all the other activities started after it, which means – all of them). Just make to have this activity in the activity stack (not finish it for some reason in advance).
- I call
finish()on this activity
This is it, works quite well for me.