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.
Ok, so I think I just figured it out.
Replaced the flag
Intent.FLAG_ACTIVITY_NEW_TASK
withIntent.FLAG_ACTIVITY_NEW_DOCUMENT
and it seems to work fine.note: this flag requires API level >= 21