Ji Sungbin
Ji Sungbin

Reputation: 1321

SingleInstance of Android launchMode

I read the official documentation and understood that singleInstance is always opened by creating a new task. So I thought that if I run two activities with the same taskAffinity, only the last opened activity will be on the back stack. However, when two activities are opened as singleInstance with the same taskAffinity, both activities are stacked on the back stack. How do I understand singleInstance?

Upvotes: 1

Views: 892

Answers (1)

David Wasser
David Wasser

Reputation: 95618

This one is pretty easy: taskAffinity trumps launchMode. This means, if you launch an Activity and that Activity has the same taskAffinity as other activities within a task, the special launchModes singleTask and singleInstance are ignored.

So unfortunately, the documentation isn't 100% correct, because there are some situations where singleInstance and singleTask launch modes do NOT behave the way they are documented.

In general, you should not be using the special launch modes singleTask or singleInstance as these come with a lot of side-effects that are not obvious. You shouldn't need these special launch modes unless you are implementing a HOME-screen replacement.

Upvotes: 2

Related Questions