Android Activity Launch Mode Example: Detailed Explaination

We often get confused with Android Activity Launch Mode when we see android:launchMode attribute associated with <activity> element in manifest file, it defines the way it will be associated to a task. A task is a collection of activities that users interact with when performing a certain job. Task uses Stack to maintain the history of activities.


Android Activity Launch Mode can be opted from any four modes as described below.

Standard (Default Launch Mode If not specified)

<activity android:launchMode="standard" />

A new instance of actvity is created everytime in the task from which it was started. Multiple instances of activity can be created and each instance may belong to different task.

SingleTop

<activity android:launchMode="singleTop" />

If instance of activity is present on top of Task stack, a new instance will not be created and system will route your intent information through onNewIntent(). If it is not presnt on top, a new instance will be created. Multiple instance can be created and each instance may belong to different task.

SingleTask

<activity android:launchMode="singleTask" />

A new task will be created and a new instance of the activity will be pushed at root of new task. If instance exists on the seperate task then system routes the call to existing instance through onNewIntent() method. Only one instance will exist at a time.

SingleInstance

<activity android:launchMode="singleInstance" />

Only one instance will exist at a time. System will not launch any other activity into task holding this type. It is always a single member of its task and activities started from here will open into seperate task.

Sample Android Application to Understand Activity Launch Mode

 

[su_button url=”https://github.com/androidsrc/ActivityLaunchMode” target=”blank” style=”stroked” background=”#51d461" color=”#ffffff” size=”6" center=”yes” radius=”0" icon=”icon: arrow-circle-o-down”]Download Full Source Code[/su_b[/su_button]p> 

ActivityLaunchMode_SamleApp

 

1. Create a  new android application project and define four activities in your application manifest one for each launch mode. 

You may also like...

10 Responses

  1. vivek says:

    Great explanation, Thanks a ton!

  2. Sajid Khan says:

    Very nice post. Great.

  3. Sameer Yadav says:

    Awesome post. very detailed and clear explanation.

  4. Dilip Chandar says:

    Very good explanation. Able to understand clearly.

  5. KC Raju Vysyaraju says:

    Awesome explanation. (Y)

  6. Satish J says:

    crystal clear explanation, thanks for the article

  7. Sequel One Solutions Pvt Ltd says:

    Like that awesome explanation thanks.

  8. Yaffa Harari says:

    so much clear explanation, with beautiful colos 😉
    thanks!

  9. Suman Boro says:

    Thank you, Nice explanation.

  1. January 13, 2016

    […] if instance of activity nowadays on top of task stack, new instance not created , scheme route intent info through onnewintent(). if not nowadays on top, new instance created. multiple instance can created , each instance may belong different task. (good post on activity launch mode) […]

Leave a Reply

Your email address will not be published. Required fields are marked *