Reputation: 111
I have an application with an activity (activity1) that pauses when pressing a button, opening a new activity (activity2) that has two buttons: a menu button and a button to resume the activity1. Pressing the menu button that opens a new activity (activity3) that has a button to get out of the application but instead of closing, it goes back to activity1, restarting it. How can I close the aplication or close the activity1 inside the activity 2 or 3?
Sorry my English. thank you very much
Upvotes: 2
Views: 470
Reputation: 4400
Pressing the menu button that opens a new activity (activity3) that has a
button to get out of the application but instead of closing,
it goes back to activity1,restarting it.
Closing a Activity from other activity?? Not Possible.
But you can achieve it(manually
) by setting a Global Variable..
Like when you press Exit Button in Activity-3
,set a Global variable(int),say "int exit"
and call finish()
in Activity 3
,this will land you in Activity-2
..Now in the OnResume Method of the Activity-2
and Activity-1
,Go On to Check the value of the Global Variable,if exit== 1
,call finish()
there.else do nothing.
Upvotes: 1
Reputation: 24233
Upvotes: 1
Reputation: 13855
When you call your activity, call finish();
straight after:
Intent intent = new Intent(getApplicationContext(),MyActivity.class);
startActivity(intent);
finish();
This will run your new activity, and close the old one in the process.
Upvotes: 1