【问题标题】:How start another package ontop of the stack?如何在堆栈顶部启动另一个包?
【发布时间】:2014-10-13 21:30:34
【问题描述】:

我必须像这样应用堆栈:

A->B-C->D

X->Y

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

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

【问题讨论】:

标签: android android-package-managers launching-application launchmode


【解决方案1】:

所以what you observe is expected. The launch modes are defined per activity,不是每个应用程序/包级别。

  • 所以要从YD,您需要使用设置为FLAG_ACTIVITY_NEW_TASK 的intent 标志启动活动D,这将确保您到达现有的D,即已经存在在您的第一个任务中处于领先地位 (A->B->C->D)

  • 要在主屏幕(启动器图标)上做同样的事情,你 may need to try below options for SingleTask mode,因为你想保留现有的堆栈 (A->B->C-D) ,只是想去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"
    

【讨论】:

  • 我不明白为什么 singleTask 会清除我的堆栈?但更重要的是:如何在不清除堆栈的情况下从我的另一个包(应用程序)重新启动另一个包(带有活动的堆栈)?
  • 但我必须在 singleTask 中有一个 IntentFilter 否则它不会出现在 Launcher -no?
  • @JohnyTex 将您的主要活动启动模式更改为标准,它将让您按原样保留堆栈(上面的第二个+point)。您仍然可以使用其他应用程序中的意图标志(例如:FLAG_ACTIVITY_NEW_TASK)以singleTask 模式重新启动另一个包。意图标志override manifest launch modes, see here.
  • 但我不想开始新任务,我想回调我的 singleTask 堆栈(!)
  • @JohnyTex it wont start new task, just brings foreground existing task(顶部带有 D)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-09
  • 2020-07-21
  • 2020-10-12
  • 2010-10-19
  • 2019-08-08
  • 1970-01-01
相关资源
最近更新 更多