问题
I am trying to wrap my head around the different options of Android's Activity launch mode (See documentation: Tasks and Back Stack
According to the documentation, when launching an activity that is marked as "singleTask":
"... Instead, either a new task starts for the Browser or, if the Browser already has a task running in the background, that task is brought forward to handle the new intent."
According to the way singleTask is described, either a new task is created, or, if the activity already exists in some other task, that task is brought forward.
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.
回答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.
回答2:
"SingleTask" - The system creates the activity at the root of a new task and routes the intent to it. However, if an instance of the activity already exists, the system routes the intent to existing instance through a call to its onNewIntent() method, rather than creating a new one.
Note: SingleTask and SingleInstance are used for specialized launches . It is not recommended for general use
From this link http://developer.android.com/guide/topics/manifest/activity-element.html
来源:https://stackoverflow.com/questions/22886953/activity-marked-as-singletask-brought-forward