52

I did not find any thread on StackOverflow that answer my question. I have already seen this Android singletop singleinstance and singletask but that question is related to his project scenario.

What are the differences between singleTask and singleInstance?? I have read the docs but could not understand..

I have read this thread also Android singleTask or singleInstance launch mode? but I could not understand. Sorry

Community
  • 1
  • 1
Mick
  • 1,179
  • 5
  • 14
  • 24

3 Answers3

56

What is unclear from the docs ?

The "singleTask" and "singleInstance" modes also differ from each other in only one respect: A "singleTask" activity allows other activities to be part of its task. It's always at the root of its task, but other activities (necessarily "standard" and "singleTop" activities) can be launched into that task. A "singleInstance" activity, on the other hand, permits no other activities to be part of its task. It's the only activity in the task. If it starts another activity, that activity is assigned to a different task — as if FLAG_ACTIVITY_NEW_TASK was in the intent.

Snicolas
  • 37,840
  • 15
  • 114
  • 173
  • 5
    So in case of `singleTask` it allows other activities in a same stack and `singleInstance` it does not allow other activities in a same stack right ?? – Mick Apr 13 '14 at 10:05
  • Any reason do you know answer of my question which I asked in comment? – Mick Apr 13 '14 at 10:18
  • Any reason why `singleInstance` keep their own `Stack` for it ?? – Mick Apr 13 '14 at 10:22
  • Because each activity has to belong to an activity Stack (called a task). – Snicolas Apr 13 '14 at 10:23
  • so each Activity associated with different `Stack` ?? – Mick Apr 13 '14 at 10:25
  • No, each activity belongs to a stack. But 2 activities can belong to the same. Analogy : each indian belongs to a tribe, but a tribe can hold more than one indian. – Snicolas Apr 13 '14 at 10:27
  • @Mick It's basically one-to-many when it come's to `singleTask`, task-to-activities, when it comes to `singleInstance`, it is one-to-one, task-to-activity – Tamim Attafi Jan 29 '23 at 22:15
36

singleTask :- A new task will always be created and a new instance will be pushed to the task as the root. However, if any activity instance exists in any tasks, the system routes the intent to that activity instance through the onNewIntent() method call. In this mode, activity instances can be pushed to the same task. This mode is useful for activities that act as the entry points.

singleInstance:- Same as singleTask, except that the no activities instance can be pushed into the same task of the singleInstance’s. Accordingly, the activity with launch mode is always in a single activity instance task. This is a very specialized mode and should only be used in applications that are implemented entirely as one activity.

since k saji
  • 893
  • 9
  • 20
8

SingleInstance is just like a singleton and also its stack is like final class can't be extended. Its always single in its stack.and always there.

Dhiraj Himani
  • 1,062
  • 12
  • 9