Android - How to finishes the all activities
My application have 10 activities. Every activity contains one button.if you click on that button then all activities will be finished(it means like Logout in gmail). Here i am using 2 steps. But it's not working. 1. Clear the stack using intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) for every activity ca开发者_Go百科lling. 2. this.finish() in button click listener.
How to implement it?
If you don't need to be back when pressing the back button,you can call finish() right after calling the intent to go another activity.So current activity is finished.So you have to finish only the last activity where you are in.
If you call welcome form login like
startActivity(login.this,welcome.class);
finish();
And when you call finish() in welcome activity your application will finish() because it is the only activity as you already finished previous activity
use FLAG_ACTIVITY_CLEAR_TOP intent flag while calling each new activity.. so what it does is it clears all the top activities and starts this new activity...now if you'll close the current activity using finish()..it'll get closed and because of FLAG_ACTIVITY_CLEAR_TOP all the others have been already closed...
it always work for me....check out the documentation for further reading..
精彩评论