tags:

views:

103

answers:

1

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.

+1  A: 

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.

Janusz