Managing the Activity Lifecycle demo activity return to original A if Start A

。_饼干妹妹 提交于 2019-12-02 16:50:26

问题


I am trying out the demo provided by https://developer.android.com/training/basics/activity-lifecycle/index.html.

I can see when I start B or C, a new activity B or C will be created, and if I Finish B or C it will be only one step backward, just like: creating A->B->C->B->C, then by finish C then B then C then B I will get to A.

Although if I try to start A in the process, it will go to the original first A, just like: creating A->B->C, then I create A, it just become A(instead of A->B->C->A).

The code for activity A, B and C look the same to me, is it because A is the main activity? do I miss something?


回答1:


It's because the launchMode for Activity A is "singleTask". This gets declared in the AndroidManifest.xml file under Activity A's <activity> tag. From this file, you can modify many aspects of the the behavior of your Activities, Services, etc. From the documentation:

In contrast, "singleTask" and "singleInstance" activities can only begin a task. They are always at the root of the activity stack. Moreover, the device can hold only one instance of the activity at a time — only one such task.



来源:https://stackoverflow.com/questions/16920741/managing-the-activity-lifecycle-demo-activity-return-to-original-a-if-start-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!