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?
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 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.
As per the image shown above, I have some queries. It is requested to read each step in order :-
Each block is an Android Activity
Arrow represents the Stack Direction - the order in which activities are opened(A is started when the app was first launched)
Here when the User reaches ACTIVITY F and want to open activity Z (We are using Flag_Activity_clear_top) for the same.
After that from ACtivity Z when the user wants to open the Activity D.
****Our Requirement at this step is - When the Activity D is opened and the user do presses the back button - I WANT THAT USER SHOULD BE REDIRECTED BACK TO THE ACTIVITY C, AFTER THAT ACTIVITY B and so on..** **
Currently when we press back from the activity D(after coming from Z), then we are being redirected to the Activity Z.
CLEAR_TOP isn't good, because if you open an activity that way, it will remove the whole stack and that doesn't sound like what you want.
Try this:
When starting activity E (from D), F (from E) and Z (from F), do it with the flag "FLAG_ACTIVITY_NO_HISTORY". This flag will prevent the new activity to appear in the back stack.
Keep in mind that any activity you open this way will not be registered in the back stack. So, if you hit back while (for example) you're in F, it will return to D.
Hope this helps!
->Incase anyone is facing the same issue. Try sending the intent along with the flags 'FLAG_ACTIVITY_CLEAR_TOP' and 'FLAG_ACTIVITY_SINGLE_TOP'.
->Example mentioned in the docs: link
Consider a task consisting of the activities: A, B, C, D. If D calls startActivity() with an Intent that resolves to the component of activity B, then C and D will be finished and B receives the sentIntent, resulting in the stack now being: A, B.
I'm developing an Android 2.2 application.
I'm very new on Android, and I see that if Iaunch a new Intent from an activity, this activity goes to paused state.
If I want that user can't goes back to this previous activity, what must I do? May I kill this previous activity with finish?
UPDATE
An example:
A, B C and D are activities.
A is the first activity.
A launches B, and B launches C, and C launches D.
I want to close or kill activity B and C when D is launched.
Thanks.
You can use your intent to startActivity like normal and follow the startActivity with
finish();
If you do this on your hypothetical activity B, you can hit the hardware back button in C and it'll take you directly to A.
You might want to rework your design. What if you have A call startActivityForResult(B, 0), and when B would have launched C, instead setResult and finish. Back in A, onActivityResult gets called, with the result you set. You can use that result as a message for A to now start the activity C.
See if that helps - http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP (This and other flags)
And also you must invoke
finish();
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.