Examples for Android Launch modes

后端 未结 2 541
太阳男子
太阳男子 2020-12-24 07:24

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 hel

相关标签:
2条回答
  • 2020-12-24 07:50

    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.

    0 讨论(0)
  • 2020-12-24 07:56

    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

    0 讨论(0)
提交回复
热议问题