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

2

11

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.

Rident answered 19/1, 2016 at 1:21 Comment(1)
They have same applicationId.Greenheart
B
16

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>
Bermudez answered 3/8, 2017 at 15:7 Comment(3)
This should be the accepted answer, FLAG_ACTIVITY_NEW_TASK actually check for task already present where as defining this flag above definition in manifest does create a separate task and you can see different activity present in recent apps stack.Additive
This must be the accepted answer as it helped me in 2020 and it nearly took my whole day to reach to solution via this answer. It throws brightest light over the question. Thanks @Bermudez and referred you here https://mcmap.net/q/1016662/-running-android-apps-particular-activity-independently-than-rest-of-activities/9810130 in my questionSwede
Up vote and Thanks for making this answer available here over SOSwede
D
0

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

Dight answered 12/3, 2017 at 13:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.