How to close an Application? [duplicate]
Possible Duplicate:
Quitting an application - is that frowned upon?
How to exit the current application on a click of any button when I am in the middle of my application?
finish() will only finish the current activity not all the activities.
In Android it is not recommended to exit an application. Read this question for more information on this.
You could use
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
to go back to the home screen on the the press of a button in your app. This will not close your application but put it in the background. You should always in every activity release every battery heavy resources like Sensor Listeners etc. the moment you are send to the background.
you can do that on button click. Define any static method like exit() and define
android.os.Process.killProcess(android.os.Process.myPid());
in exit method
in the main or first activity.
Then call this method on button click.
精彩评论