活动标记为" SingleTask"带领向前

时间:2014-04-05 21:18:41

标签: android android-intent android-activity launchmode

我正试图围绕Android的活动启动模式的不同选项(参见文档:Tasks and Back Stack

根据文档,在启动标记为" singleTask"的活动时:

  

" ...相反,要么为浏览器启动新任务,要么启动   浏览器已经有一个在后台运行的任务,该任务是   提出来处理新的意图。"

根据singleTask的描述方式,创建一个新任务,或者,如果该活动已经存在于某个其他任务中,则该任务将被提前。

如果浏览器活动的实例(例如)已经存在于我的应用程序活动的同一任务(堆栈)中(但不在前台),会发生什么?它是如何提出来的?这没有在文档中描述。

2 个答案:

答案 0 :(得分:1)

You asked:

What happens in case an instance of the Browser activity (for example) already exists in the same task (stack) of my app's activity (but not in the foreground) ? How is it brought forward? This is not described in the doc.

It is not possible for an instance of the Browser activity (to use your example) to exist in your app's task stack, because that Activity has been defined with singleTask launch mode and has a different taskAffinity from the other activities in your app. Therefore, whenever the Browser activity is launched, it will always be launched into its own task, and not into your task.

答案 1 :(得分:0)

“SingleTask” - 系统在新任务的根目录创建活动并将意图路由到该任务。但是,如果活动的实例已经存在,系统会通过调用onNewIntent()方法将意图路由到现有实例,而不是创建新实例。

注意:SingleTask和SingleInstance用于专门的启动。不建议用于一般用途

从此链接 http://developer.android.com/guide/topics/manifest/activity-element.html