I have two apps App-B launches App-A. If the user starts App B from inside App A I call finish on App-A so I have no problem.
If the user goes straight to App B from the Application drawer or long pressing home button then I implement the below which clears the task in App A first before applying all the extras. This has the desired affect but only works on API 11. On lower APIs the new task in APP-A will not change and extras putExtra will have no effect. Any alternative to FLAG_ACTIVITY_CLEAR_TASK
? for API <=10?
Intent i = new Intent("com.App-A");
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
Thanks
Jason
The new IntentCompat should've helped on that, but apparently the flag is ignored for API lower than 11.
To use IntentCompat do following:
this will work correctly
I'm still having a lot of trouble understanding the problem but would like to help you fix it. Since comments only allow 600 characters and don't format well, I'm going to create an answer instead, because I'm sure that together we can get this resolved.
I would like to be able to reproduce your problem. To do that I've created 2 applications: AppA and AppB. AppA has a single activity called
ActivityA
and AppB has a single activity calledActivityB
. BothActivityA
andActivityB
useandroid:launchMode="singleTask"
.ActivityA
has a button on it that launches AppB and finishes, like this:ActivityB
has a button on it that launches AppA like this:This all works as I expect it to. AppA and AppB run in different tasks. The "extra" is properly seen in the
onCreate()
methods of each application.So, can you please tell me more about your problem. How can I reproduce exactly your problem? You wrote:
What do you mean by that? Where are you putting extras and where are you getting them and what do you expect to happen?
Also, what is the
launchMode
of yourAppB
?Also, when you have this problem, are there other activities in the task stack for AppA?
Please provide more info, either in your original question or here as comments.
Using
FLAG_ACTIVITY_CLEAR_TASK
clears the back stack. If I'm understanding correctly, this is the behavior you want.Using
singleInstance
instead ofsingleTask
in your manifest will do this.In the comments you said that it must be
singleTask
. I'm assuming this is because you need the back stack in certain circumstances.Since
launchMode
can't be changed programaticaly andFLAG_ACTIVITY_CLEAR_TASK
is not availble for API <=10, you may have to create two identical activities.One with
launchMode=singleTask
and one withlaunchMode=singleInstance
.Add this to the one using
singleInstance
to get a clear stack when launched from the app drawer:I may be wrong in understanding what you are asking, but is it that when you launch B, you want A to be killed?
In A, add this to the activity tag in the manifest:
This will cause the activity to be removed from memory as soon as it loses focus.
The best documentation I've found for these Intent flags is here: http://blog.akquinet.de/2010/04/15/android-activites-and-tasks-series-intent-flags/
I don't understand what you are trying to do, but have you tried
FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
?