In my android application suppose several activities are there if using intent I go to other activities like this
[Activity A]->[activity B]->[Activity C]->[Activity-D]->[Activity N]
and now when am on activity N when I pressed button then I want to go to Activity B and want to destroy Activity C And Activity D but Activity A should not destroy. I also searched in various posts but I didn't get exactly the same solution. Any help will be appriciated
In ActivityN
, to return to ActivityB
use this:
Intent intent = new Intent(this, ActivityB.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
Using the flag CLEAR_TOP
will finish all activities in the stack that are on top of ActivityB
. In the example you gave, this will finish ActivityN
, ActivityD
and ActivityC
. Using the flag SINGLE_TOP
will make sure that this will return control to the existing instance of ActivityB
(ie: it won't create a new instance of ActivityB
).
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