0

I'm trying to start an intent with Main2Activity in a new (separate) task (i.e. separate back stack and separate instance in recents screen). I realized that the way it should be done is adding the Intent.FLAG_ACTIVITY_NEW_TASK and Intent.FLAG_ACTIVITY_MULTIPLE_TASK intent flags:

Intent intent = new Intent(this, Main2Activity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
startActivity(intent);

But this only works if I set (in the manifest) Main2Activity's android:taskAffinity to other than the default (i.e. other than the current activity's task affinity).

The problem is that I want to be able to create another new task with the same activity more than once.

Example:

In the android Gmail app, you can click the "compose" button several times, and each time it creates a "new instance" of the composer. I'd like to achieve the exact same behavior.

Any clue?

Thanks a lot.

Yoav B
  • 21
  • 1

2 Answers2

2

Ok, so I think I just figured it out.

Replaced the flag Intent.FLAG_ACTIVITY_NEW_TASK with Intent.FLAG_ACTIVITY_NEW_DOCUMENT and it seems to work fine.

note: this flag requires API level >= 21

Yoav B
  • 21
  • 1
0

Instead of using

Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK

You have to use only

Intent.FLAG_ACTIVITY_MULTIPLE_TASK

because documents says that FLAG_ACTIVITY_NEW_TASK brings the old task in front if already started and create new task only if not running.

DiLDoST
  • 335
  • 3
  • 12