Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Examples for Android Launch modes

Tags:

I am finding it hard to understand the exact circumstances in which each the various launch modes would be used in Android. Could anyone provide me with some examples to help understand when the various modes are appropriate?

like image 483
Casebash Avatar asked Apr 13 '10 00:04

Casebash


2 Answers

Between the Browser and Alarm Clock applications, you cover all four launch modes:

  1. BrowserActivity uses singleTask. There is only one browser activity at a time and it doesn't become part tasks that send it intents to open web pages. While it might return to whatever most recently launched it when you hit back it is actually fixed at the bottom of its own task activity stack. It will share its task with activities that it launches like bookmarks.

  2. BrowserBookmarksPage uses singleTop. While there can be multiple instances of this activity, if there is already one at the top of the task's activity stack it will be reused and onNewIntent() will be called. This way you only have to hit back once to return to the browser if the bookmarks activity is started multiple times.

  3. AlarmClock uses standard. The user can launch multiple instances of this activity and these instances can be part of any task and anywhere in the activity stack. As a fairly simple application it doesn't really demand tight control of its activity.

  4. AlarmAlert uses singleInstance. Only one alert activity at a time and it is always its own task. Anything it launches (if anything) becomes part of its own new task.

like image 161
Tim Kryger Avatar answered Oct 06 '22 11:10

Tim Kryger


The official documentation is a bit confusing so here's a table to help.

http://androidisland.blogspot.com/2010/12/activity-launch-modes-simple.html

like image 41
Eurig Jones Avatar answered Oct 06 '22 09:10

Eurig Jones