Monday , 1 May 2017
Home » Personal » Communities » Android Activity Launch Modes

Android Activity Launch Modes

No matter how I read a bunch of words from the documentation about Activity Launch Modes, it just takes too damn long to understand. Here’s a table showing you what launch modes to use for activities you have.

Behavior Mode standard singleTop singleTask singleInstance
Can be launched by other activities? Y Y N N
Can have multiple instances? Y Y N N
Can launch other child activites? Y Y Y N
Reuse if activity is at the top of the stack? N Y N N

And here’s what kind of activity you should set for each mode:

Type of Activity Mode
Root Activity singleTask
One Activity Only singleInstance
Other Activity standard

Frankly, I don’t know when I will use singleTop mode. If anyone knows a type of activity that suits singleTop, please put a comment and tell me when you will use singleTop mode.

Here’s a common scenario though. What happens if you want to float an existing instance of Activity to the top of the stack? For example, your current stack is (bottom)A-B-C-D(top) and you want to float B to the top of the stack like this (bottom)A-C-D-B(top). You “start” the activity with an intent with the flag FLAG_ACTIVITY_REORDER_TO_FRONT like the following:

[sourcecode language=”java”] intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

I think that covers most of the usages of Activity Launch Modes for Android. Hopefully more Android titbits to come in future.

About Justin Lee

Check Also

Editor of STOMP Ostracizes Google Android Platform when receiving SiTF Award

Mr. Chew V Ming (right), Editor of STOMP, ostracized the Google Android Platform not once …

Leave a Reply