Reputation: 1885
If I have an Activity A starting Activity B which starts a different instance of Activity A, I would like to go back to the previous Activity A (the first one in the back stack), and so I've tried using the intent flag FLAG_ACTIVITY_CLEAR_TOP, but of course this recognizes the top activity as the running instance rather than the first one. How do I get rid of the second instance of Activity A & Activity B to resume my session back to the first Activity A?
A - > B - > A - > Go back to first A and finish second A & B.
My target is API Level 10.
Upvotes: 0
Views: 189
Reputation: 22342
Try these flags:
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK );
From the docs for FLAG_ACTIVITY_CLEAR_TASK:
... this flag will cause any existing task that would be associated with the activity to be cleared before the activity is started. That is, the activity becomes the new root of an otherwise empty task, and any old activities are finished. This can only be used in conjunction with FLAG_ACTIVITY_NEW_TASK.
Note that it will not only clear the activities, but create a whole new task. This may not be ideal if, for example, Activity A is not your "home" activity.
Upvotes: 1
Reputation: 3576
you can try by setting flag FLAG_ACTIVITY_SINGLE_TOP. otherwise you will need to monitor your activities yourself and route to where is needed when needed.
Upvotes: 0
Reputation: 9434
You could try setting FLAG_ACTIVITY_NO_HISTORY when activity B starts the second instance of Activity A. No guarantees, but it might work.
Of course if activity B is cooperating, you could return a status from the second instance of A that B could recognize and immediately finish() itself. That doesn't really address the problem if you have A->B->C-A, though.
Upvotes: 1