I’ve got the following:
Activities A, B, C, D. A and D can be reached at any time, anywhere from the application.
B and C are reached like this:
A -> B -> C
I have the following use case:
The user has entered C ( A -> B -> C ) then she has gone to D.
When she wants to go to A, I want to transfer her to the already started queue from A – in other words I want her to go to the started C.
Something like this A -> B -> C -> D -> (same) C. But I don’t want to lose D from the activity stack. After this, when she presses the "back" button, she is transfered to D again.
Is this possible and correct to do? What is the best practice?
Unfortunately you can’t do this. The documentation says the following:
Basically you can’t have the same instance of Activity C in two places in the stack at the same time.
However, you could make it appear that this was the case by making Activity C save its transient state to the
Applicationobject for your application. This would allow all instances of Activity C to share state and so appear as if they were the same instance.You’d need to create your own subclass of
Applicationand then read and write to it from Activity C inonResume()andonPause().