For example I have four activity A, B, C, and D. I go from A to B and from B to C and then from C to D.
Now in Activity D, on particular button click, I want to destroy Activity D as well as activity C and want to jump on activity B. Now when I click on back button in activity B, then it should navigate me on activity A. please help someone how can I achieve this functionality.
Note: I do not want to destroy activity C while navigating from activity C to activity D
In D, when you want to navigate back to B, do this:
Intent intent = new Intent(this. ActivityB.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
This will cause A and D to be removed from the stack, B will now be shown in whatever state it was in when you left it, and onNewIntent() will be called on B.
Related
I have activity A that starts activity B which starts activity C:
A -> B -> C
When a user clicks on a button in activity C, I want to bring A to the top of the stack and take B & C completely out of the stack. Is there a way to do this?
You can use the FLAG_ACTIVITY_CLEAR_TOP flag on the intent to restart activity A.
I have 5 activities (A, B, C and D).
A -> B -> C -> D
On activity B and C, if we press the return button, I would like the previous activity to be called (respectively A and B).
Activity D is an end activity without a return button.
When I use "finish ()", it's currently going back to Activity C.
I would like to go back directly to activity A when we reach activity D by executing finish() without going through B and C.
However since B I must always be able to return to A and too C can back to B.
"A" is an activity in launchMode singleTop.
android: noHistory = true on activity D does not allow me to return directly to A.
The only solution I have found for the moment is to use startActicity (A) instead of "finish ()" but I find that this solution is not a good pararique.
Do you have a solution to my problem?
In your D activity use this:
Intent i = new Intent(this, YourFirstActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
This way, you'll return exactly to your A activity.
I'm stuck with an Activity backstack question. Let's say I have 5 activities in my backstack: like Activity A, Activity B, Activity C, Activity D and Activity E. At some point I want the user to go to another Activity G, when pressed on the back button on Activity E. Activity G needs to be put after Activity B, so I want Activity C and Activity D removed from the backstack (otherwise the user would go to Activity D).
Current situation A --> B --> C --> D --> E
Preferred situation A --> B --> G
Now I understand I can use FLAG_ACTIVITY_CLEAR_TOP when Activity G would have been in the backstack. But the Activity isn't. Also I don't want to use FLAG_ACTIVITY_NEW_TASK because then Activities A and B would also be gone.
Another approach would be to put
android:noHistory="true"
within the manifest for Activities C and D, but this would make the user go back to Activity B every time the user pressed the back button from within Activity C or D.
Who can point me in the right direction?
You can try below
C ----startActivityForResult----------> D ---startActivityForResult--> E
handle onActivityResult with result accordingly to finish Activities, make sure its chained action calls
When you start activity from C->D you put finish();
Intent intent=new Intent(C.this,D.class);
startActivity(intent);
finish();
same way for D->G this way it is possible.
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 have activity A that starts activity B which starts activity C:
A -> B -> C
When a user clicks on a button in activity C, I want to bring A to the top of the stack and take B & C completely out of the stack. Is there a way to do this?
You can use the FLAG_ACTIVITY_CLEAR_TOP flag on the intent to restart activity A.