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.
how to keep multiple activities of the same app in the recent-apps list
Asked Answered
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>
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 question –
Swede
Up vote and Thanks for making this answer available here over SO –
Swede
The trick is to start the new Activity via an Intent
with FLAG_ACTIVITY_NEW_TASK
flag enabled.
© 2022 - 2024 — McMap. All rights reserved.