Metadesign Solutions

Android Launch Mode

Android Launch Mode
  • September 13, 2022
  • Amit Gupta
  • 6 minutes read

Blog Description

Android Launch Mode

Android Launch Mode

Launch mode is an Android OS command that determines how the activity should be started. It specifies how every new action should be linked to the existing task.

There are four launch modes for activity.

  • Standard

  • SingleTop

  • SingleTask

  • SingleInstance

back-stack

Figure 1. A representation of how each new activity in a task adds an item to the back stack. When the user presses or gestures Back, the
current activity is destroyed and the previous activity resumes.

Standard:

This is the default launch mode of activity. If you don’t set any launch mode to your activity, it will use the standard mode by default. It creates a new instance of activity every time even if the activity instance is already present.

Suppose we have A, B, C, and D activities and your activity B has Standard launch mode. Now again launching activity B

State of Activity Stack before launch B

A →B→ C→D

State of Activity Stack after launch B

A → B → C→D→ B

We can see that new instance of B is created again.

Syntex

<activity android:launchMode=”standard” />

SingleTop:

If an instance of activity already exists at the top of the current task, a new instance will not be created and the Android system will route the intent information through
onNewIntent().

If an instance is not present on top of the task then a new instance will be created.

Suppose we have A, B, C, and D activities. A →B →C →D

If we launch C then a new instance of C will be created as it is not on top.

So it will look like A →B →C →D →C

Now suppose we have A →B →C →D →C like this

then we again launch C activity then in this case a new instance will not be created. Instead, we will receive the callback on onNewIntent() method.

Syntex

<activity android:launchMode=”singleTask” />

SingleTask:

An activity declared with launch mode as singleTask can have only one instance in the system (singleton). At a time only one instance of activity will exist.

If activity instance is not present then the new instance will be created and if the instance is already present in the system then the onNewIntent() method will receive the callback.

Suppose we have A, B, C activities (A →B →C ) and we are launching D that has a singleTask launch mode. In that case, the new instance of D will be created so the current state will look like this. (A →B →C →D)

Now let suppose if we launch B that also have has a singleTask launch mode then current state will look like this.

A →B

Here old instance gets called and intent data route through onNewIntent() callback. Also, notice that C and D activities get destroyed here.

<activity android:launchMode=”singleTop” />

Figure 2. A representation of how an activity with launch mode “singleTask” is added to the back stack. If the activity is already a part
of a background task with its own back stack, then the entire back stack also comes forward, on top of the current task.

SingleInstance:

It is similar to singleTask except that no other activities will be created in the same task. If another Activity is called from this kind of Activity, a new Task would be automatically created to place that new Activity.

Case 1:

Suppose you have A, B, and C activities (A →B →C) and your activity D has a singleInstance launch mode. In this case, if we launch D then D will be launch in the diffrent task. New task for D will be created.

Task1: A →B →C

Task2 : D (here D will be in the different task)

Now if you continue this and start E and D then Stack will look like

Task1: A →B →C →E

Task2: D

Case 2:

Suppose you have A, B, C activities in one task (A →B →C) and activity D is in another task with launch mode singleInstance. In this case, if we launch D again then we will receive the callback in the onNewIntent() method of D activity.

Task1: A →B →C

Task2: D (Here old instance gets called and intent data route through onNewIntent() callback)

<activity android:launchMode=”singleInstance” />

Conclusion

As we explore the intricacies of Android launch modes and their impact on app development, it’s also important to consider the broader landscape of cross-platform solutions. In the realm of mobile app development, technologies like Flutter and React Native are changing the game, offering developers the tools to build high-performance, visually appealing applications for both Android and iOS from a single codebase. Our Flutter app development services and React Native development services are tailored to meet the evolving needs of businesses looking to expand their mobile presence efficiently. By leveraging these powerful frameworks, our team ensures that your app delivers a seamless user experience, regardless of the platform. Embrace the future of mobile app development with us, where innovation meets versatility, and excellence is a standard.

0 0 votes
Blog Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Scroll to Top

GET a QUOTE

Contact Us for your project estimation
We keep all information confidential and automatically agree to NDA.

About

MetaDesign Solutions is an innovative IT company dedicated to delivering cutting-edge technology solutions tailored to meet the unique needs of its clients.