3

I want to show 2 different activities of one app at recent apps by calling 2 different activities like the image below. How can I do that?

enter image description here

Nabin Bhandari
  • 15,949
  • 6
  • 45
  • 59
begiNNer
  • 128
  • 12

1 Answers1

4

For API Level 21 or above, it can simply be accomplished by setting the flag Intent.FLAG_ACTIVITY_NEW_DOCUMENT in the intent.

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);

If your minimum API level is less than 21, you can make use of the activity attribute taskAffinity in the manifest.

<activity
    android:name="com.example.ActivityOne"
    android:taskAffinity="app.two" />

<activity
    android:name="com.example.ActivityTwo"
    android:taskAffinity="app.two" />

After setting different affinities, launching the activities as singleInstance or setting the flag Intent.FLAG_ACTIVITY_NEW_TASK will make the two activities appear separately in the recents.

<activity
    android:name="com.example.ActivityTwo"
    android:launchMode="singleInstance"
    android:taskAffinity="app.two" />

OR

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Nabin Bhandari
  • 15,949
  • 6
  • 45
  • 59