android:launchMode概述

android:launchMode
An instruction on how the activity should be launched. There are four modes that work in conjunction with activity flags (FLAG_ACTIVITY_* constants) in Intent objects to determine what should happen when the activity is called upon to handle an intent. They are:
"standard"
"singleTop"
"singleTask"
"singleInstance"

The default mode is "standard".

Activity有四种启动模式,默认为标准型。还是先给出表格,看的更加清楚。

Use Cases Launch Mode Multiple Instances? Comments
Normal launches for most activities  "standard" Yes Default. The system always creates a new instance of the activity in the target task and routes the intent to it.
"singleTop" Conditionally If an instance of the activity already exists at the top of the target task, the system routes the intent to that instance through a call to its onNewIntent() method, rather than creating a new instance of the activity.
Specialized launches (not recommended for general use)  "singleTask" No The system creates the activity at the root of a new task and routes the intent to it. However, if an instance of the activity already exists, the system routes the intent to existing instance through a call to its onNewIntent() method, rather than creating a new one.
"singleInstance" No Same as "singleTask", except that the system doesn‘t launch any other activities into the task holding the instance. The activity is always the single and only member of its task.

"standard"可以有多个相同实例,并且每次启动一个Activity,系统总是在任务栈中创建一个Activity新的实例并且为它设置意图的路径。

"singleTop"的多个实例是有条件的,如果一个Activity的实例已经存在与任务栈顶端,系统通过调用它的onNewIntent()函数来为意图设置到此实例的路径而非创建一个新的相同实例。

以上两个是常用的。

后两个不常用。

"singleTask"只有一个实例。在当前任务栈中,如果实例不存在,则会创建一个,如果这个Activity的实例已经存在,系统通过调用它的onNewIntent()函数来为意图设置到此实例的路径而非创建一个新的实例,即会结束它上面全部的Activity。如果另一个程序启动了这个Activity,并且此Activity已经在当前任务栈中创建,则不会在那个任务栈创建实例,而是使用引用指向当前任务栈中的实例。

例如:

B为singleTask模式

操作:A->B          A->B->C          A->B->C->B            A->B->C->B->C->A             A->B->C->B->C->A->B
实际:A->B          A->B->C          A->B                              A->B->C->A                               A->B

"singleInstance"Activity总是独占一个任务栈。如果A中启动B,系统为B另外开辟一个任务栈。

时间: 2024-07-29 23:53:20

android:launchMode概述的相关文章

android视图概述

android视图概述 一.简介 数据和控件分开的作用: 便于引用 便于修改:修改的时候直接改一次数据就可以了

android launchMode理解以及应用场景

在我们写应用的时候,常常涉及多个activity组件之间的跳转.比如说某个资讯的页面中,点击下一篇资讯跳转相同的页面,只有页面的数据不一样.一般情况下我不会注意launchMode 这个属性,只会使用默认的,这样会产生大量重复的activity.那是因为之前不了解,所以特此研究学习. 1.如何指定launchMode 基本上我们可以直接指定一个launchMode属性在AndroidManifest.xml 文件中 <activity android:name=".views.MainAc

Android数据加密概述及多种加密方式 聊天记录及账户加密 提供高质量的数据保护

Android数据加密概述及多种加密方式 聊天记录及账户加密 提供高质量的数据保护 数据加密又称密码学,它是一门历史悠久的技术,指通过加密算法和加密密钥将明文转变为密文,而解密则是通过解密算法和解密密钥将密文恢复为明文.数据加密目前仍是计算机系统对信息进行保护的一种最可靠的办法.它利用密码技术对信息进行加密,实现信息隐蔽,从而起到保护信息的安全的作用. 一.概述 数据加密是指通过加密算法和加密密钥将明文转变为密文,而解密则是通过解密算法和解密密钥将密文恢复为明文.它产生的历史相当久远,它是起源于

来自Android LaunchMode的温馨提示

西西说 作为一只安卓小白,还是愿意和大家分享我的探索旅程,那么就让我们先来一点来自Android launchMode的温馨提示吧~(≧▽≦)/~. 背景知识 "现在我的手中有一摞牌,但是我让你看到的只有一张." "其他牌去哪了呢?" "其他张牌都被最上面这张牌挡住了呀." 上面的这段话,很形象地解释了acitivity和任务栈的关系. 接下来我们首先了解一下任务--Task. Task Task 是activities的集合,通过back st

[Learn Android Studio 汉化教程]第二章:Android Studio概述(一)

[Learn Android Studio ]第二章:Android Studio概述(一) Android Studio是一个视窗化的开发环境.为了充分利用有限的屏幕空间,不让你束手束脚,Android Studio 在特定的时间仅仅显示一小部分可用窗口.除了一些上下文敏感的窗口和上下文相关的窗口显示出来外,其他的仍旧隐藏,除非你主动打开它们.或者相反,一些可见的窗口直到你主动隐藏它们.为了充分利用Android Studio,你就需要明白这些窗口的功能以及如何.何时去显示它们.在这一章,我们

Android LaunchMode案例篇

首先感谢小伙伴的关注.然后祝愿广大的情侣们节日快乐! 在开发中有时会遇到这种场景,用户点击注冊.第一步,第二步,完毕注冊跳转到登录界面,不须要用户一步一步的返回到登录界面.这是怎么实现的呢? 案例:有四个界面 A.B,C.D 从A跳转到B.B跳转到C,C跳转到D,D完毕注冊跳转到A,点击返回键退出程序.详细过程来看下图: 这里提供了三种常见的解决方式. 方案一 1.清单文件(AndroidManifest.xml)文件设置A的启动模式 <activity android:name=".A&

android launchmode 使用场景

菜鸟起飞记 android launchmode 使用场景 Activity一共有以下四种launchMode: 1.standard 2.singleTop 3.singleTask 4.singleInstance 一,引用场景分析 1.standard 是默认的系统启动模式,每次启动activity都会新建一个实例,也就是说即使启动相同的activity ,他所产生的对象也是不同的. 该种模式大多用于 页面切换的 中间页,每次都是新页面(适用于大多场景). 2.singleTop 单一栈顶

android launchmode(四种启动模式)应用场景及实例

模式介绍 [1] standard 模式 这是默认模式,每次激活Activity时都会创建Activity实例,并放入任务栈中. [2] singleTop 模式 如果在任务的栈顶正好存在该Activity的实例,就重用该实例( 会调用实例的 onNewIntent() ),否则就会创建新的实例并放入栈顶,即使栈中已经存在该Activity的实例,只要不在栈顶,都会创建新的实例. [3] singleTask 模式 如果在栈中已经有该Activity的实例,就重用该实例(会调用实例的 onNew

android:launchMode的四种方式

Activity一共有以下四种launchMode: standard singleTop singleTask singleInstance 1.standard standard模式是默认的启动模式,不用为<activity>配置android:launchMode属性即可,当然也可以指定值为standard. 我们将会一个Activity,命名为FirstActivity,来演示一下标准的启动模式.FirstActivity代码如下: package com.scott.launchmo