2

Scenario:

I have MainActivity, which has <intent-filter>s MAIN and LAUNCHER. This activity is set to have launchMode="singleTask" by required design.

I navigate in some path: MainActivity -> Activity A -> Activity B, which are all added to the task stack.

Scenario A: I background the app, resume it from the Recent Apps section. Task stack is resumed correctly e.g. B > A > Main

wm_task_moved: [269,0,2147483647]
am_focused_stack: [0,0,234,0,moveTaskToFront findTaskToMoveToFront]
wm_task_moved: [269,0,2147483647]
am_on_top_resumed_lost_called: [0,com.google.android.apps.nexuslauncher.NexusLauncherActivity,topStateChangedWhenResumed]
correct behavior --> am_set_resumed_activity: [0,test.ActivityB,moveTaskToFront findTaskToMoveToFront]
am_pause_activity: [0,60517111,com.google.android.apps.nexuslauncher/.NexusLauncherActivity,userLeaving=true]
am_task_to_front: [0,269]
am_on_paused_called: [0,com.google.android.apps.nexuslauncher.NexusLauncherActivity,performPause]
am_set_resumed_activity: [0,test.ActivityB,resumeTopActivityInnerLocked]
am_add_to_stopping: [0,60517111,com.google.android.apps.nexuslauncher/.NexusLauncherActivity,makeInvisible]
am_resume_activity: [0,29773184,269,test.ActivityA]
sysui_multi_action: [757,803,799,window_time_0,802,6]
am_on_restart_called: [0,test.ActivityB,performRestartActivity]
am_on_start_called: [0,test.ActivityB,handleStartActivity]
am_on_resume_called: [0,test.ActivityB,RESUME_ACTIVITY]
am_on_top_resumed_gained_called: [0,test.ActivityB,topWhenResuming]
sysui_multi_action: [319,30,321,25,322,123,325,110814,757,761,758,9,759,4,806,test.package,871,test.ActivityB,904,test.package,905,0,1320,12,1321,1]
am_stop_activity: [0,60517111,com.google.android.apps.nexuslauncher/.NexusLauncherActivity]
am_on_stop_called: [0,com.google.android.apps.nexuslauncher.NexusLauncherActivity,STOP_ACTIVITY_ITEM]

Scenario B: I background the app again, and this time resume it from the launcher icon; the Activity is flagged somehow, and clears the task stack, leaving only the root MainActivity.

incorrect behavior --> am_finish_activity: [0,262811058,269,test.ActivityA,clear-task-stack]
incorrect behavior --> am_destroy_activity: [0,262811058,269,test.ActivityA,finish-imm:finishActivityLocked]
incorrect behavior --> am_finish_activity: [0,214943796,269,test.ActivityB,clear-task-stack]
incorrect behavior --> am_destroy_activity: [0,214943796,269,test.ActivityB,finish-imm:finishActivityLocked]
am_new_intent: [0,24608519,269,test.Main,android.intent.action.MAIN,NULL,NULL,268435456]
wm_task_moved: [269,0,2147483647]
am_focused_stack: [0,0,234,0,bringingFoundTaskToFront]
wm_task_moved: [269,0,2147483647]
am_set_resumed_activity: [0,test.Main,bringingFoundTaskToFront]
am_pause_activity: [0,60517111,com.google.android.apps.nexuslauncher/.NexusLauncherActivity,userLeaving=true]
am_task_to_front: [0,269]
sysui_multi_action: [757,803,799,window_time_0,802,9]
sysui_multi_action: [757,803,799,window_time_0,802,0]
am_on_top_resumed_lost_called: [0,com.google.android.apps.nexuslauncher.NexusLauncherActivity,topStateChangedWhenResumed]
am_on_paused_called: [0,com.google.android.apps.nexuslauncher.NexusLauncherActivity,performPause]
am_set_resumed_activity: [0,test.Main,resumeTopActivityInnerLocked]
am_add_to_stopping: [0,60517111,com.google.android.apps.nexuslauncher/.NexusLauncherActivity,makeInvisible]
am_resume_activity: [0,24608519,269,test.Main]
incorrect behavior --> am_on_destroy_called: [0,test.ActivityA,performDestroy]
sysui_multi_action: [757,803,799,window_time_0,802,0]
incorrect behavior --> am_on_destroy_called: [0,test.ActivityB,performDestroy]
am_on_restart_called: [0,test.Main,performRestartActivity]
am_on_start_called: [0,test.Main,handleStartActivity]
I am_on_resume_called: [0,test.Main,RESUME_ACTIVITY]
am_on_top_resumed_gained_called: [0,test.Main,topWhenResuming]

The event log for scenario 2; it seems to be forcibly setting clear-task-stack on ActivityB & ActivityA when launching from the app icon vs Recent Apps.

To my knowledge, if I declare my activity as singleTask, when I re-launch the app from the app icon, it should find the existing task stack and recreate it, same as in Scenario A. The only conclusion I can come to is that launching the application from the app icon is flagging it somehow, which is overriding some inherent behavior to a singleTask Activity and manually resetting the task stack.

I believe this is a bug, but please correct me if I am wrong. I'm seeking clarity as to why the two scenarios act differently, and how I might workaround this if it is a bug, or change my implementation if it's intended behavior. I have read on SO about similiarly bugged behavior, but it differs in that I do not have a separate Launch activity of any kind; just a single MainActivity with defined intent-filter attributes for MAIN and LAUNCHER, while also being a singleTask activity. My MainActivity is still seeing itself as the root task; it's just clearing the other tasks when, I believe, it should not be.

The only solution I see right now is to change my MainActivity to launchMode="singleTop" and manually flag each time I'm starting it to avoid instance duplication, which seems to defeat the purpose of singleTask entirely.

Any help is appreciated; thanks!

Shan
  • 41
  • 4

0 Answers0