What is the difference between android: launchMode="singleTask" and android: launchMode="singleInstance"?

2

Good morning, I'm investigating the launch modes of the activities on android.

I am developing an application where there should only be one instance of an activity (A), if it were the case that there were more instances of the activity could cause errors in the execution of the application, investigating a little, reach the point of find these two ways to start activities

android:launchMode="singleTask"  y   android:launchMode="singleInstance"

In play store I found this app that shows how types of activity launches on Android work link The problem is that when I start these activities in both modes they seem to do the same and I do not want to make a mistake in which to choose to start my activity, I hope you can help me to identify the difference between both launch modes, since I did not understand the information very well from the official documentation, thank you in advance

Official documentation: link

    
asked by Alvaro Fabian M 20.02.2018 в 04:38
source

1 answer

2

To understand the difference, you can check the documentation for which the "singleTask" and "singleInstance" modes are intended:

Activity android: launchMode

  

The activities "singleTask" and "singleInstance" only   You can start a task. They are always at the root of the pile   of activities. In addition, the device can only handle one   instance of the activity at the same time; just one of that task.

In the case of an activity defined as "singleInstance", it does not allow other activities to be part of its task. It is the only activity in the task. If another activity is started, that activity is assigned to a different task, as if FLAG_ACTIVITY_NEW_TASK was set to Intent .

Therefore the difference is:

The "singleTask" and "singleInstance" modes differ from each other in a single aspect: a "singleTask" activity allows other activities to be part of your task, while "singleInstance" does not.

    
answered by 20.02.2018 / 16:15
source