What I am trying to do :
I am currently in
Activity A
(in app A). I launch anActivity B
(in app B) usingstartActivity()
. Once I am done withActivity B
, instead of just finishing it and expectingActivity A
to show up, I actually restoreActivity A
with an intent in caseActivity A
was killed in the background.
Current dumpsys
logs :
When in Activity A
Stack #0:
Task id #23
userId=0 effectiveUid=u0a123 mCallingUid=0 mUserSetupComplete=true mCallingPackage=null
affinity=com.domain.appA
intent={act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10800100 cmp=com.domain.appA/.ActivityA}
realActivity=com.domain.appA/.ActivityA
When Activity B
is launched
Stack #1:
Task id #25
userId=0 effectiveUid=u0a99 mCallingUid=u0a123 mUserSetupComplete=true mCallingPackage=com.domain.appA
affinity=com.domain.appB
intent={act=MY_ACTION flg=0x10000000 cmp=com.domain.appB/com.domain.appB.ActivityB}
realActivity=com.domain.appB/com.domain.appB.ActivityB
Stack #0:
Task id #23
userId=0 effectiveUid=u0a123 mCallingUid=0 mUserSetupComplete=true mCallingPackage=null
affinity=com.domain.appA
intent={act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10800100 cmp=com.domain.appA/.ActivityA}
realActivity=com.domain.appA/.ActivityA
When Activity A
is launched from Activity B
Stack #1:
Task id #26
userId=0 effectiveUid=u0a123 mCallingUid=u0a99 mUserSetupComplete=true mCallingPackage=com.domain.appB
affinity=com.domain.appA
intent={act=ACTION_FOR_A flg=0x10820000 cmp=com.domain.appA/.ActivityA}
realActivity=com.domain.appA/.ActivityA
Stack #0:
Task id #23
userId=0 effectiveUid=u0a123 mCallingUid=0 mUserSetupComplete=true mCallingPackage=null
affinity=com.domain.appA
intent={act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10800100 cmp=com.domain.appA/.ActivityA}
realActivity=com.domain.appA/.ActivityA
Erratic behavior observed :
Activity A
instead of being resumed, is actually being instantiated again resulting in 2 instances and breaking the flow because the 2nd instance is a new one resulting in onCreate()
being called whereas the continuity of requires onNewIntent()
being called.
NOTE:
I am launching the Activity B
using flag FLAG_ACTIVITY_NEW_TASK
because I want Activity B
to be persisted even if Activity A
is killed in the background.
Desired behavior :
When sending an intent from
Activity B
forActivity A
,Activity A
should resume if it is still alive in the background and should be instantiated in case it has been killed in the background.
Possible solution I am thinking here is maybe there is some flag I can set in the intent while launching Activity B
so that there is only Stack #0
and no Stack #1
. The second stack being created seems to be issue here.
I would be able to better understand if someone can also clarify the difference between task
and stack
because this does not seem to be consistent with what a task
is portrayed to be in Android documentation.
User contributions licensed under CC BY-SA 3.0