Question

Suppose there are 4 activity A->B->C->D
and if i launch the the activity B from D.then what is Flow of stack.
(what will happen in stack)

A--------->B-------->C---------->D and i start the activity B from D.and press the back button while in activity B that time it will come to A and after that application destroy. so my question is that what happen with activity C and D.

Was it helpful?

Solution

If your stack looks like this:

A->B->C->D

and you start activity B from activity D (without using any special launch flags) then a new instance of activity B will be created and your stack will look like this:

A->B->C->D->B

where there are now 2 instances of activity B in the stack (these are 2 different objects!).

If you now press the BACK button, you will return to activity D and your stack will look like this:

A->B->C->D

If, however, your stack looks like this:

A->B->C->D

and you start activity B from activity D (using Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) then the existing instance of activity B will be moved to the front and your stack will look like this:

A->C->D->B

If you now press the BACK button, you will return to activity D and your stack will look like this:

A->C->D

If, however, your stack looks like this:

A->B->C->D

and you start activity B from activity D (using Intent.FLAG_ACTIVITY_CLEAR_TOP) then activities B, C, and D will be finished and a new instance of activity B will be created and your stack will look like this:

A->B

If you now press the BACK button, you will return to activity A and your stack will look like this:

A
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top