简体   繁体   中英

Android launchMode singleTask

If we have 2 activities, A and B , both defined as singleTask in AndroidManifest.xml , when A starts B , A will be closed ( onDestroy() being called immediately). Why does this happen, and how to avoid A to be closed by the system (multiple singleTask activities in same application)?

From documentation:

"singleTask" and "singleInstance" activities can only begin a task. They are always at the root of the activity stack.

Since there cannot be two root activities in the system, all the previous activities are closed when starting such a task.

Can you provide example code and the manifest that exhibits this problem? In order to reproduce it I've created a simple 2-Activity application where both activities have launchMode="singleTask" and where the Activit1 launches Activity2. This works as expected (Activity1 is not immediately destroyed). I imagine that you are doing something else either in your code or in your manifest that causes the behavior you are describing. Please post code and manifest so we can help with your problem.

从我测试的onDestroy开始,不会在Android 5.1上启动

也许这与任务亲和力有关

我有同样的问题。我将活动B的启动模式设置为“singleInstance”,它解决了问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM