For Activity A, B, C and D I have a flow like A->B->C->D. When I'm going to start D from C I need to clear A and B from back stack.
Related
I have application A, and application B.
In A, it has a, b, c activities.
In B, it has x activity and there is a button to launch b activity in A.
Assume in back stack there are already activities a, b, c (c at the top) in task 1.
Now get c to start an activity x, result in x is created in task2. (Based on what I read from the introduction on lollipop).
Then click the button in x, it will start b activity. b is then created in a separate task. I consider it normal because the launch mode is standard. If I launch b with Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT flag (For some reasons, I cannot give b singleTask launch mode, so use the flag instead). b is brought to front, however, c is killed (Based on what I read, this is expected behavior).
Now I want to know how can I just reorder b to the top without destroying c? which will make the back stack become a, c, b.
I have tried FLAG_ACTIVITY_REORDER_TO_FRONT but does not work.
I ended up adding a blank activity in application A, which is called by x, this brings task 1 to the top, then in this activity, I launch b with FLAG_ACTIVITY_REORDER_TO_FRONT flag and finish itself or just noHisotry flag in manifest file.
I'm having a problem deciding how to handle the UP button.
Activity C and D are two ways to view downloaded material.
Activity B is to select among already downloaded material.
Activity A is the starting activity, and the one where material is selected for download.
A stack could look like these:
A, B, C, D
A, B, D, C
A, B, C
A, B, D
And the stack could look the same sans B:
A, C, D
A, D, C
A, C
A, D
The parent of B is obviously A:
Parent(B) = A
The parent for C an D however is more tricky. I think a user would assume they would return to select another already downloaded material if that was what they were doing beforehand. Otherwise they would assume they would return to the start of the app:
Parent(C) = Parent(D) = "B if it exists in the stack; A otherwise"
Two problems:
1) It seems like the official Android guides on navigation only consider the possibility that an activity has one single activity as parent.
2) I have not been able to figure out an elegant way to accomplish this (which supports problem 1). However I've considered solution a and b:
a) Making every activity pop to the parent through a chain of onNewIntent until the onNewIntent of A or B stops it. Whichever comes first.
b) Having a static stack structure onto which parents are pushed and popped so that a C or D activity can go to A or B directly. Whichever is on the top of the parent stack.
I chose a third solution:
I have an extra called parentString in C and D. A and B gives the appropriate parentString to C and D when starting them. C and D pass it along to the other. When the up button is selected in C and D parentString is used to determine what activity to pop back to.
I use the activities' class.toString as parentString.
I have some activities A, B, C, D. No the way it's set up is like this.
When user starts the app, activity A starts.
Based on a preference, which if set to true, immediately starts activity D
From there D starts C and C starts B which then starts A
... At this point i want D, C, B removed from the back stack so that user cant go back to them by pressing back from A (but the back button should work like it should when in D, B, C).
so to sum it up i need something like this
D <--> C <--> B --> A
I tried using intent flags Intent.FLAG_ACTIVITY_CLEAR_TOP & Intent.FLAG_ACTIVITY_NEW_TASK
but they dont work.
How do i accomplish this??
Then start activity A with FLAG_ACTIVITY_TASK_ON_HOME flag set.
Ok.
How about calling finish on B after launching A?
I've noticed a strange behaviour when not adding a framgent transaction to the back stack. I have 4 fragments: A, B, C and D. The transaction for the C fragment isn't added to the back stack. First I add A, then B, then C. Then I press BACK. A is displayed, which is normal. Then I add D and I press BACK. The result is that the fragment C is displayed. Is there something I am missing, because I would expect C to be out of the back stack and to see fragment A.
The transaction for the C fragment isn't added to the back stack.
ok.
First I add A, then B, then C. Then I press BACK. A is displayed,
If you have added B to the backstack, it should display B and not A.
Then I add D and I press BACK.
If you have not added C, then it should show B and not C. If it is showing C that means that you have added C to the backstack.
Is there something I am missing.
From my understanding of the situation, you have not added B to the backstack and you have added C to the backstack.
Support App starts activity A, then A starts activity B and finishes itself. After that activity B starts activity C.
Now the stack contains B and C, with C at the top.
Then I click a button in activity C, and want it to clear B and C and start activity A, i.e. I want activity A to be the only activity in the stack. How can I make it?
Edit: I made a test to use FLAG_ACTIVITY_CLEAR_TOP. But it didn't work in my case, because activity A is not running when button in activity C is clicked.
Set the FLAG_ACTIVITY_CLEAR_TOP flag on your intent to start activity A.
Edit: Is there a reason you can't leave A going? Then you could do as suggested.
Otherwise, another (more complicated) option:
In B start C forResult. When A is started from C, you could finish C with a result indicating to B to also exit.