I have 4 Android activities. Let's call them A, B, C, D.
The normal flow is A => B => C => D. However, when I enter D I want to remove B and C from the back stack.
Is it solvable?
Note that if the user is in C and presses back, B should still be displayed!
Edit: Starting activity A again with CLEAR_TOP did call onCreate again on Activity A which I do not want. Any other solutions?
I know this is an old question, but I recently had the same issue, and couldn't find a solution anywhere. The only solution I could get to work is a bit of a hack:
Start C from B using startActivityForResult.
Intent intent=new Intent(this,C.class);
startActivityForResult(intent,REQUEST_CODE);
In Activity C, create the intent for Activity D and set it as a result:
Intent intent=new Intent(this,D.class);
setResult(RESULT_OK,intent)
finish();
In Activity B, finish and start the intent returned from Activity C:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode==REQUEST_CODE) {
finish();
startActivity(data);
}
}
At this point, both activities B and C will be finished and the activity stack will be A => D
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With