Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finish all activities at a time

I have an application with multiple pages i.e., multiple activities and some of them remain open.

Is there a way to close all activities at once?

like image 496
steve Avatar asked Dec 22 '12 10:12

steve


People also ask

How do you finish multiple activities?

When the user is on Activity D and click a button called exit, the application should go back to Activity B and finish the Activities C and D.

How do you finish an activity?

On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.


1 Answers

Whenever you wish to exit all open activities, you should press a button which loads the first Activity that runs when your application starts then clear all the other activities, then have the last remaining activity finish. to do so apply the following code in ur project

Intent intent = new Intent(getApplicationContext(), FirstActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra("EXIT", true); startActivity(intent); 

The above code finishes all the activities except for FirstActivity. Then we need to finish the FirstActivity's Enter the below code in Firstactivity's oncreate

if (getIntent().getBooleanExtra("EXIT", false)) {     finish(); } 

and you are done....

like image 88
letsnurture Avatar answered Sep 29 '22 05:09

letsnurture