Need single activity in new task backstack

帅比萌擦擦* 提交于 2019-12-11 09:28:55

问题


It is nightmare when must deal with android task and launching modes(flags).

Need accomplish this scenario:

From background service launch Activity[1] that belongs to App[A] in new task. When user go [back] - finish activity[1] and resume whatever App was previously in foreground!

If App[A] was active and running - there is no problem, [beck] close Activity[1] and resume App[A]. But if any other App[B] is in foreground at the moment when launching Activity[1] (even with the new Task) all App[A] tasks and stacks came forward over App[B] and broke [back] navigation. I suppose to see App[B] after navigating back from Activity[1].

Tried several flag combination, but none of them accomplish what needed.

Suitable only when App[A] running:

                Intent.AddFlags(ActivityFlags.NewTask);
                Intent.AddFlags(ActivityFlags.ReorderToFront);
                Intent.AddFlags(ActivityFlags.ExcludeFromRecents);

Suitable only when App[B] running (clears App[A] backstack):

                Intent.AddFlags(ActivityFlags.NewTask);
                Intent.AddFlags(ActivityFlags.ClearTask);
                Intent.AddFlags(ActivityFlags.ExcludeFromRecents);

How to configure Intent to launch only one independed Activity[1] and go back to resume whatever was previously on screen?


回答1:


I think the Intent.FLAG_ACTIVITY_MULTIPLE_TASK flag will do

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);


来源:https://stackoverflow.com/questions/22513352/need-single-activity-in-new-task-backstack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!