How to exit from the application and show the home screen?

poojan9118 picture poojan9118 · Jul 12, 2010 · Viewed 328.1k times · Source

I have an application where on the home page I have buttons for navigation through the application.

On that page I have a button "EXIT" which when clicked should take the user to the home screen on the phone where the application icon is.

How can I do that?

Answer

ognian picture ognian · Jul 12, 2010

Android's design does not favor exiting an application by choice, but rather manages it by the OS. You can bring up the Home application by its corresponding Intent:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);