对于Android发射模式的示例示例、模式、Android

2023-09-05 08:48:28 作者:pretend △假装

我发现很难了解确切的情况,其中每个不同的启动模式将在Android中使用。谁能给我提供一些例子来帮助理解,当各种各样的方式是适当的?

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?

推荐答案

之间的Browser和Alarm时钟应用程序,涵盖所有四个发射模式:

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

BrowserActivity使用 singleTask 。只有一次一个浏览器的活性和它不会成为该发送它的Intent打开网页部分任务。虽然它可能返回到任何最近推出了它,当你打回它实际上是固定在了自己的任务活动栈底。它将与它推出如书签活动分享自己的任务。

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.

BrowswerBookmarksPage使用 singleTop 。虽然可以有这个活动的多个实例,如果已经有一个在任务的活动堆栈顶部它将被重新使用和onNewIntent()将被调用。这样,您只需打回来一次,如果书签活动开始多次返回到浏览器。

BrowswerBookmarksPage 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.

AlarmClock使用标准。用户可以启动该活动的多个实例,并且这些实例可以是任何任务中的活动的任何地方栈的一部分。作为一个相当简单的应用程序并不真正需要它的活动严格控制。

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.

AlarmAlert使用 singleInstance 。仅一次一个它警报活动,并且总是它自己的任务。任何它启动(如果有的话)成为自己的新任务的一部分。

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.