问题
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