Home > DeveloperSection > Forums > Launch mode in modes in android
ben reitman
ben reitman

Total Post:96

Posted on    August-05-2015 11:56 PM

 Android Android 

 1 Reply(s)
 1329  View(s)
Rate this:
What are “launch modes”? What are the two mechanisms by which they can be defined? What specific types of launch modes are supported?

Mayank Tripathi
Mayank Tripathi

Total Post:397

Posted on    August-06-2015 7:50 AM

A “launch mode” is the way in which a new instance of an activity is to be associated with the current task.

Launch modes may be defined using one of two mechanisms:

Manifest file. When declaring an activity in a manifest file, you can specify how the activity should associate with tasks when it starts. Supported values include:

standard (default). Creates a new instance of the activity in the task from which it was started and route the intent to it.
singleTop. If an instance of the activity already exists at the top of the current task, the system routes the intent to that instance through a call to its onNewIntent() method, rather than creating a new instance of the activity.
singleTask. Creates a new task and instantiates the activity at the root of the new task. However, if an instance of the activity already exists in a separate task, the system instead routes the intent to the existing instance through a call to its onNewIntent() method. Only one instance of the activity can exist at a time.

Intent flags. Calls to startActivity() can include a flag in the Intent that declares if and how the new activity should be associated with the current task. Supported values include:

FLAG_ACTIVITY_NEW_TASK. Same as singleTask value in Manifest file (see above)

FLAG_ACTIVITY_SINGLE_TOP. Same as singleTop value in Manifest file (see above).

FLAG_ACTIVITY_CLEAR_TOP. If the activity being started is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it are destroyed and this intent is delivered to the resumed instance of the activity (now on top), through onNewIntent(). There is no corresponding value in the Manifest file that produces this behavior.

Don't want to miss updates? Please click the below button!

Follow MindStick