How to switch to an Activity that is running through an already running Activity
I know there are much discussions about this but i cannot get this to work properly.
Activity
(A) = singleTop
and can receive android.intent.action.SEND
Activity
(B) = singleTask
When i from the Android Gallery select a picture and open it with (A)
The (A) is redirecting the intent to (B).This is working ok and if i press HOME and select (A) from the luncher the (B) is brought to front. That is what i want and user can continue with picture,
Now, if i press HOME and open the Android Gallery again the (A) is
onRestart()
, OnStart()
and onResume()
. and i see (A).
This is the problem i like to switch to (B) because user need to finish what he was doing.
I cannot see a good way to do that and why does the Android Gallery resume (A)?
Maybe i do something wrong since opening the Android Gallery bring me (A) Any help wou开发者_Go百科ld be appreciatedThis is possible reasoning based on limited info in the question, assuming A is redirecting the intent to B in its onCreate().
1) Open Gallery, select a picture, open with A, redirect it to B
Task1 has stack has Gallery, A, B (B on top of the stack)
2) Press home, select A from launcher
Launcher app creates a new task, new task2's stack has a new instance of activity A, its onCreate() is invoked and intent is redirected to B. B being a singleTask is moved from Task1 to Task2 and its onNewIntent() would be invoked.
3) Press home, and open gallery
Task1 is resumed and the top of the stack is now A. Its onRestart(), onStart() and onResume() is invoked.
This being the scenario, you can try redirecting the intent from A's onStart() or do not have B as singleTask.
UPDATE
I know this is an intricate scenario. I have made a working solution by simply killing (A)/finish() after the launch of (B). Now,
if i press HOME and open the Android Gallery again i see Android Gallery.
if i press HOME and open A i see B.
if i press back from B I see the gallery
精彩评论