代码编织梦想

        其实“最近使用的应用”屏幕添加链接描述 这篇文章已经写的很清楚了,但是网上的很多介绍都是翻译的api文档,让人看了一头雾水,这里再给大家科普一下。

        首先要知道Android的最近任务里面的显示是以任务为单位的, 一般清空下Android程序按照应用按照应用包名来组织task, 或者按照taskAffinity来组织逻辑上的应用。 同一个Activity不能单独的出现在不同的activity task中,也就是没法在多任务中看到多个任务。 这显然是满足用户使用体验的,比如用户使用WPS打开两篇文档,如果把这两篇文档放在同一个task中,就只能销毁其中一篇才能看到另外一篇。为了解决这个问题Android 5.0开始引入documentLaunchMode。有了documentLaunchMode,如果同一 Activity 的多个实例包含不同的文档,它们可能会在最近使用的应用屏幕中显示为任务。比如说,Google 云端硬盘的几个 Google 文档可能各自都有一个任务。每个文档都会在最近使用的应用屏幕中显示为任务。

         所以documentLaunchMode的目的就是将相同的Activity启动到不同的task中,以便在最近任务中进行切换。

         知道了documentLaunchMode的设计就好理解documentLaunchMode的作用了
> 这里是引用
      要了解上面的含义还是需要知道FLAG_ACTIVITY_MULTIPLE_TASK标志的作用, FLAG_ACTIVITY_MULTIPLE_TASK标志强制将Activity启动到一个新的task, 所以intoExisting模式其实就是如果已经存在可复用的Activity则不会启动新的Task。 always表示创建Activity总是到新的Task中。 none模式表示和普通的standard行为一致。 never标志表示即使启动该Activity设置了FLAG_ACTIVITY_NEW_DOCUMENT和FLAG_ACTIVITY_MULTIPLE_TASK标记也不会将Activity启动到单独的Task中。

      再来看下FLAG_ACTIVITY_NEW_DOCUMENT 标志, 其实就是FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET标志,在Android 5.0开始该标志已经作废,我们可以看下4.4中的定义。

    /**
     * This flag is used to open a document into a new task rooted at the activity launched
     * by this Intent. Through the use of this flag, or its equivalent attribute,
     * {@link android.R.attr#documentLaunchMode} multiple instances of the same activity
     * containing different documents will appear in the recent tasks list.
     *
     * <p>The use of the activity attribute form of this,
     * {@link android.R.attr#documentLaunchMode}, is
     * preferred over the Intent flag described here. The attribute form allows the
     * Activity to specify multiple document behavior for all launchers of the Activity
     * whereas using this flag requires each Intent that launches the Activity to specify it.
     *
     * <p>Note that the default semantics of this flag w.r.t. whether the recents entry for
     * it is kept after the activity is finished is different than the use of
     * {@link #FLAG_ACTIVITY_NEW_TASK} and {@link android.R.attr#documentLaunchMode} -- if
     * this flag is being used to create a new recents entry, then by default that entry
     * will be removed once the activity is finished.  You can modify this behavior with
     * {@link #FLAG_ACTIVITY_RETAIN_IN_RECENTS}.
     *
     * <p>FLAG_ACTIVITY_NEW_DOCUMENT may be used in conjunction with {@link
     * #FLAG_ACTIVITY_MULTIPLE_TASK}. When used alone it is the
     * equivalent of the Activity manifest specifying {@link
     * android.R.attr#documentLaunchMode}="intoExisting". When used with
     * FLAG_ACTIVITY_MULTIPLE_TASK it is the equivalent of the Activity manifest specifying
     * {@link android.R.attr#documentLaunchMode}="always".
     *
     * Refer to {@link android.R.attr#documentLaunchMode} for more information.
     *
     * @see android.R.attr#documentLaunchMode
     * @see #FLAG_ACTIVITY_MULTIPLE_TASK
     */
    public static final int FLAG_ACTIVITY_NEW_DOCUMENT = FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;

也就是说从桌面重新恢复关联任务后,会清除document类型的activity,防止用户不知所措(多任务不会)。

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接: https://blog.csdn.net/woai110120130/article/details/111092009

使用最新版本Android NDK-r21 编译 opencv-3.3.1 + opencv_contrib-3.3.1-爱代码爱编程

由于新版本的NDK跟旧版本NDK编译的opencv存在兼容问题,所以需要使用最新的NDK重新编译opencv,方法步骤如下: Android NDK-r21 编译 opencv-3.3.1 + opencv_contrib-3.3.1 1. sudo apt-get install cmake 2. 官网下载NDK: android-ndk-r21,

叶子相似的树(Java)-爱代码爱编程

考虑一棵二叉树上所有的叶子,这些叶子的值按从左到右的顺序排列形成一个叶值序列 如上图所示,给定一棵叶值序列为 (6, 7, 4, 9, 8) 的树。 如果有两棵二叉树的叶值序列是相同,那么我们就认为它们是叶相似的。 如果给定的两个头结点分别为 root1 和 root2 的树是叶相似的,则返回 true;否则返回 false 。 示例 1: 输

Fragment的传值应用-爱代码爱编程

Fragment高级应用 Fragment的传值activity给fragment传值fragment给activity传值fragment给fragment传值 Fragment的传值 不同页面之间的传值是最基本的要求 activity给fragment传值 getArguments()和setArguments() 一

ViewPager的使用及与Fragment的区别-爱代码爱编程

Viewpager的使用) View的介绍ViewPager与Fragment结合使用 ( 重 点 )Fragment 和Viewpager的区别 View的介绍 使用效果图 View的介绍 Viewpager,视图翻页工具,提供了多页面切换的效果。Android3.0后引入的一个UI空间,位于v4包中。低版本使用需要导入v4包,但是

MT2712 Boot Flow Introduction-爱代码爱编程

  Boot Flow OverviewBootROM IntroduceBL2 stageTEE+ATFBL33 stageMT2712 Image Format  Boot Flow Overview ARM64处理器上电以后,首先执行地址0x0000_0000的bootroom代码,bootrom将引导程序加载到内部SRAM执行。MTK平台使用

深入浅出安卓中封装组件的三种方法-爱代码爱编程

文章目录 前言一、封装组件样式二、include标签+layout布局文件封装组件三、自定义组件1、复合组件(继承布局)2、修改现有组件(继承某个基础组件)3、完全自定义组件(继承View或ViewGroup) 前言 在大前端中,有一些组件常常需要在不同的地方多次使用,但不可能在每一个地方都重新编写组件代码,因此组件的封装就显得格外重要。本篇