0

我必须像这样应用堆栈:

A->BC->D

X->Y

在 Y 我想使用 getLaunchIntentForPackage("package") 到 D,但是我到了 A。我应该使用什么启动模式等?如果可能的话,我想将 singleTask 用于 ABCD。同样,当在 D 中时,我按下 home 并再次通过 A 图标启动,然后根据启动模式,我没有到达 D(我想要的),但到达 A。DCB 被清除。

我尝试了很多东西,但我就是不明白它是如何工作的。我似乎没有得到相应的行为。

4

1 回答 1

1

所以你观察到的都是预期的。启动模式是按活动定义的,而不是按应用程序/包级别定义的。

  • 因此,要从YtoD开始,您需要D使用设置为 的意图标志开始活动FLAG_ACTIVITY_NEW_TASK,这将确保您到达现有的D,这已经在您的第一个任务(A->B->C->D)中处于首位

  • 要从主屏幕(启动器图标)执行相同操作,您可能需要尝试以下SingleTaskmode选项,因为您想保留现有堆栈 (A->B->CD) ,并且只想获取D; 引用链接:

    "+ For launchMode=singleTask if there is an intent_filter in the
    manifest the task stack is always cleared after returning to Home and
    re-launching (returns to main activity instead of last activity).
    
    + For launchMode=standard re-launch from Home instead returns to last
    activity in task (as expected).
    
    + If there is no intent_filter listed then even with
    launchMode=singleTask re-launch from Home returns to the last activity
    in the task"
    
于 2014-10-14T00:03:29.927 回答