When my stack is in this situation:
A->B->C
if I start D activity, I want that the activity stack becomes:
A->D
Note that activity C is a dialog.
When my stack is in this situation:
A->B->C
if I start D activity, I want that the activity stack becomes:
A->D
Note that activity C is a dialog.
here is a better solution not depending on evaluating the
Intent
content inA
: use the flagFLAG_ACTIVITY_TASK_ON_HOME
you should also take a look at the other flags Android Intent
here are the steps which will do the needed:
fromActivityC
bundled with the intent and the flagFLAG_ACTIVITY_CLEAR_TOP
set .Now in the on create of the activity A check for this boolean "fromActivityC" first and if present launch the activity D else the normal flow continues.
A lil workaround but Hope it helps
on callback of C , pass a message back to A and start your D from Acall finish , this will finish B and C (because C is apart of B).
There is several way to remove a activity from the stack or prevent it to be stacked :
To remove your activity from the stack , simply call
finish()
, see here.You can also implement in your manifest the property : android:noHistory="true" which prevent an activity to be stacked.
See this question form more detail : Removing an activity from the history stack
You could try finishing
ActivityB
when you launchActivityC
and the same inActivityC
when launching A.Your code would look like this:
A little hacky, but you could start activity A while clearing the stack, then start activity D.
Activity A might appear for a moment before disappearing though