简体   繁体   English

Android启动模式的示例

[英]Examples for Android Launch modes

I am finding it hard to understand the exact circumstances in which each the various launch modes would be used in Android. 我发现很难理解在Android中使用各种启动模式的确切情况。 Could anyone provide me with some examples to help understand when the various modes are appropriate? 任何人都可以提供一些例子来帮助理解各种模式何时适合?

Between the Browser and Alarm Clock applications, you cover all four launch modes: 浏览器闹钟应用程序之间,您将涵盖所有四种启动模式:

  1. BrowserActivity uses singleTask . BrowserActivity使用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 . BrowserBookmarksPage使用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. 虽然可以有多个此活动的实例,但如果在任务的活动堆栈的顶部已经存在一个,则将重用它并且将调用onNewIntent() 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 . AlarmClock使用标准 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 . AlarmAlert使用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. 它启动的任何东西(如果有的话)都会成为它自己新任务的一部分。

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 http://androidisland.blogspot.com/2010/12/activity-launch-modes-simple.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM