Arvis
Arvis

Reputation: 8363

Need single activity in new task backstack

It is nightmare when must deal with android task and launching modes(flags).

Need accomplish this scenario:

From background service launch Activity[1] that belongs to App[A] in new task. When user go [back] - finish activity[1] and resume whatever App was previously in foreground!

If App[A] was active and running - there is no problem, [beck] close Activity[1] and resume App[A]. But if any other App[B] is in foreground at the moment when launching Activity[1] (even with the new Task) all App[A] tasks and stacks came forward over App[B] and broke [back] navigation. I suppose to see App[B] after navigating back from Activity[1].

Tried several flag combination, but none of them accomplish what needed.

Suitable only when App[A] running:

                Intent.AddFlags(ActivityFlags.NewTask);
                Intent.AddFlags(ActivityFlags.ReorderToFront);
                Intent.AddFlags(ActivityFlags.ExcludeFromRecents);

Suitable only when App[B] running (clears App[A] backstack):

                Intent.AddFlags(ActivityFlags.NewTask);
                Intent.AddFlags(ActivityFlags.ClearTask);
                Intent.AddFlags(ActivityFlags.ExcludeFromRecents);

How to configure Intent to launch only one independed Activity[1] and go back to resume whatever was previously on screen?

Upvotes: 1

Views: 832

Answers (1)

Hoan Nguyen
Hoan Nguyen

Reputation: 18151

I think the Intent.FLAG_ACTIVITY_MULTIPLE_TASK flag will do

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);

Upvotes: 1

Related Questions