How To Finish Every Activity On The Stack Except The First In Android
I'm porting an iPhone app to Android and I can't seem to find a means to pop each activity on the stack except the root activity. In objective-c I would do something like the below
Solution 1:
If you want to start one Activity, say, your homescreen, and remove every other Activity in your application's stack, you can use:
Intent intent = newIntent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Removes other Activities from stackstartActivity(intent);
If you also want to provide this event in the MainActivity (such as a logo click in the title bar), you can add the FLAG_ACTIVITY_SINGLE_TOP flag as well to make sure it does not add another instance of itself to the stack.
Solution 2:
Look at http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP: you can startActivity on the root activity with this flag, and it will blow away all activities above it. You should read the docs carefully about the intent delivery behavior.
Post a Comment for "How To Finish Every Activity On The Stack Except The First In Android"