Java_Android
Java_Android

Reputation: 745

Close all activities and come to mobile's home screen

When I press the log out button and come to start(main) screen and when I press the back button from main screen it comes to 2nd screen. but, i want to close the application on click of back button from main screen and close all the activities before that. while doing research I found,

Intent intent = new Intent(this, Home.class);  
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);  
finish();

but its not satisfying my requirement.

Upvotes: 0

Views: 1228

Answers (2)

Rishabh Bhardwaj
Rishabh Bhardwaj

Reputation: 831

just add line in your code and this will work fine

   startActivity(intent);

Upvotes: 0

Rachita Nanda
Rachita Nanda

Reputation: 4659

You can use this code that I referred from here How to exit from the application and show the home screen?:

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

Although Android's design does not favor exiting an application by choice.

Related Links:

How to close Android application?

Android exit application

Upvotes: 3

Related Questions