我有2个活动:活动A和活动B.活动A的启动模式是标准的,活动B的启动模式是singleTask.
android:name=".AActivity"
android:label="@string/app_name"
android:launchMode="standard">
android:name=".BActivity"
android:label="@string/app_name"
android:launchMode="singleTask">
我启动了应用程序,启动器启动了活动A.然后我按下主页按钮并返回到手机的主屏幕.然后我启动浏览器应用程序并输入以下内容:
dd://b
打开活动B.系统导航到我的应用程序并在活动A之上启动活动B.此时,如果我按回按钮,活动B将弹出,我看到活动A.
这不是我所期望的,因为android文档说明:
For singleTask activities,the system creates a new task and instantiates the activity at the root of the new task. However,if an instance of the activity already exists in a separate task,the system routes the intent to the existing instance through a call to its onNewIntent() method,rather than creating a new instance. Only one instance of the activity can exist at a time.
我从这些句子中理解的是,在我的情况下,因为活动B的实例不存在,所以应该启动一个新任务,它应该只有活动B在它的堆栈(我的应用程序的另一个实例应该仍然存在于单独的任务,它的堆栈中应该有活动A.然后,如果我在活动B时按回,因为它是后台堆栈中的唯一活动,它会弹出并且系统返回到浏览器.
为什么不是这样的? android系统如何知道我的应用程序是打开并导航到它并在现有应用程序堆栈上启动活动B而不是启动我的应用程序的另一个实例并让我的应用程序的两个实例拥有自己的堆栈?在新任务中实例化活动意味着什么?谁能解释一下?
谢谢.