Reputation: 870
I need to start an activity called ActivityA
and clear all the other activities that were launched in the same task. It can be done pretty easily using combination of Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
flags. The problem here is that I do not want to recreate ActivityA
if it's already been started as the root of the task (I want to remove all of the other activities though). Consider this:
If I have A -> B -> C -> D, then I just want to close B, C and D and then return to A.
If I have B -> C -> A -> D, then I want to remove all of the activities and recreate activity A.
Is there a way to do so?
EDIT:
There's another important aspect I forgot to mention: ActivityA
is can be used in multiple different apps, so there's no way I can do anything with B, C, D or any other activity.
Upvotes: 2
Views: 63
Reputation: 795
<activity
android:name=".B"
android:noHistory="true" />
Add android:noHistory="true" to your activities B, C, D. Now, when you press the back button, you will be returned to activity A
Upvotes: 1