How to quit terminal
Please think really hard about if you do need to kill the application: why not let the OS figure out where and when to free the resources?
Otherwise, if you're absolutely really sure, use
As a reaction to @dave appleton's comment: First thing read the big question/answer combo @gabriel posted: Quitting an application - is that frowned upon?
Now assuming we have that, the question here still has an answer, being that the code you need if you are doing anything with quitting is finish(). Obviously you can have more than one activity etc etc, but that's not the point. Lets run by some of the use-cases
- You want to let the user quit everything because of memory usage and "not running in the background? Doubtfull. Let the user stop certain
activities in the background, but let the OS kill any unneeded recourses.
- You want a user to not go to the previous activity of your app? Well, either configure it so it doesn't, or you need an extra option. If most of the time the back=previous-activity works, wouldn't the user just press home if he/she wants to do something else?
- If you need some sort of reset, you can find out if/how/etc your application was quit, and if your activity gets focus again you can take action on that, showing a fresh screen instead of restarting where you were.
So in the end, ofcourse, finish() doesn't kill everthing, but it is still the tool you need I think. If there is a usecase for "kill all activities", I haven't found it yet.Source: stackoverflow.com