how to keep multiple activities of the same app in the recent-apps list

最后都变了- 提交于 2019-12-09 03:09:16

问题


I have one app with two activities A & B, both with launch mode singleInstance. I notice that even if both A and B are running in the background, only the last activity is shown in recent-apps list. Is it possible to keep both A & B in the recent-apps list? Thanks.


回答1:


In the AndroidManifest, make sure to set the android:taskAffinity attribute of the element differently for each Activity. For example:

<activity
    android:name="com.example.ActivityA"
    android:label="Activity A"
    android:launchMode="singleInstance"
    android:taskAffinity="com.example.AffinityA" >
</activity>
<activity
    android:name="com.example.ActivityB"
    android:label="Activity B"
    android:launchMode="singleInstance"
    android:taskAffinity="com.example.AffinityB" >
</activity>



回答2:


The trick is to start the new Activity via an Intent with FLAG_ACTIVITY_NEW_TASK flag enabled.



来源:https://stackoverflow.com/questions/34866998/how-to-keep-multiple-activities-of-the-same-app-in-the-recent-apps-list

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