Activity的5种启动模式详解(新增singleInstancePerTask类型)

news2024/9/23 15:22:41

前言

看到这个标题的时候,也许你会认为我写错了,Activity不是只有四种启动模式吗?分别为startard,singleTop,singleTask,singleInstance这四种。

一般来说是四种,但是android12的时候新加入了singleInstancePerTask类型,所以就有5种了。

介绍这五种类型之前,我们先略微介绍一下这五种类型在源码中的定义。

首先,我们先看一下官方注释的位置下,这五种类型的注释在attrs_manifest.xml文件中:

<attr name="launchMode">
        <!-- The default mode, which will usually create a new instance of
             the activity when it is started, though this behavior may change
             with the introduction of other options such as
             {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK
             Intent.FLAG_ACTIVITY_NEW_TASK}. -->
        <enum name="standard" value="0" />
        <!-- If, when starting the activity, there is already an
            instance of the same activity class in the foreground that is
            interacting with the user, then
            re-use that instance.  This existing instance will receive a call to
            {@link android.app.Activity#onNewIntent Activity.onNewIntent()} with
            the new Intent that is being started. -->
        <enum name="singleTop" value="1" />
        <!-- If, when starting the activity, there is already a task running
            that starts with this activity, then instead of starting a new
            instance the current task is brought to the front.  The existing
            instance will receive a call to {@link android.app.Activity#onNewIntent
            Activity.onNewIntent()}
            with the new Intent that is being started, and with the
            {@link android.content.Intent#FLAG_ACTIVITY_BROUGHT_TO_FRONT
            Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT} flag set.  This is a superset
            of the singleTop mode, where if there is already an instance
            of the activity being started at the top of the stack, it will
            receive the Intent as described there (without the
            FLAG_ACTIVITY_BROUGHT_TO_FRONT flag set).  See the
            <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
            Stack</a> document for more details about tasks.-->
        <enum name="singleTask" value="2" />
        <!-- Only allow one instance of this activity to ever be
            running.  This activity gets a unique task with only itself running
            in it; if it is ever launched again with the same Intent, then that
            task will be brought forward and its
            {@link android.app.Activity#onNewIntent Activity.onNewIntent()}
            method called.  If this
            activity tries to start a new activity, that new activity will be
            launched in a separate task.  See the
            <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
            Stack</a> document for more details about tasks.-->
        <enum name="singleInstance" value="3" />
        <!-- The activity can only be running as the root activity of the task, the first activity
            that created the task, and therefore there will only be one instance of this activity
            in a task. In constrast to the {@code singleTask} launch mode, this activity can be
            started in multiple instances in different tasks if the
            {@code FLAG_ACTIVITY_MULTIPLE_TASK} or {@code FLAG_ACTIVITY_NEW_DOCUMENT} is set.-->
        <enum name="singleInstancePerTask" value="4" />
    </attr>

其次,在看一下这五种模式在Java文件中的定义,在ActivityInfo类中,如下:

    /**
     * Constant corresponding to <code>standard</code> in
     * the {@link android.R.attr#launchMode} attribute.
     /
    public static final int LAUNCH_MULTIPLE = 0;
    /*
     * Constant corresponding to <code>singleTop</code> in
     * the {@link android.R.attr#launchMode} attribute.
     /
    public static final int LAUNCH_SINGLE_TOP = 1;
    /*
     * Constant corresponding to <code>singleTask</code> in
     * the {@link android.R.attr#launchMode} attribute.
     /
    public static final int LAUNCH_SINGLE_TASK = 2;
    /*
     * Constant corresponding to <code>singleInstance</code> in
     * the {@link android.R.attr#launchMode} attribute.
     /
    public static final int LAUNCH_SINGLE_INSTANCE = 3;
    /*
     * Constant corresponding to <code>singleInstancePerTask</code> in
     * the {@link android.R.attr#launchMode} attribute.
     */
    public static final int LAUNCH_SINGLE_INSTANCE_PER_TASK = 4;

接下来,我们就依次讲解这五种类型的定义和作用。

一.standard类型

首先讲解standard类型,这也是一个最基本最常用的一种类型。

官方解释

先看官方注释中的描述:

        <!-- The default mode, which will usually create a new instance of
             the activity when it is started, though this behavior may change
             with the introduction of other options such as
             {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK
             Intent.FLAG_ACTIVITY_NEW_TASK}. -->

翻译后:

默认的类型,每次使用时通常创建一个新的活动对象,虽然这样的行为会因为引入其它参数配置而发生改变,比如Intent.FLAG_ACTIVITY_NEW_TASK。

实验验证

我们再来通过实验进行验证,创建三个Activity,分别为Test1Activity,Test2Activity,Test3Activity,如下:

        <activity android:name="com.xt.client.activitys.test.Test1Activity" />
        <activity android:name="com.xt.client.activitys.test.Test2Activity" />
        <activity android:name="com.xt.client.activitys.test.Test3Activity" />

然后我们在代码中设置如下跳转顺序:Test1->Test2->Test3->Test1

接下来就是实验,按照上面流程跳转后,使用adb命令捕获当前Activity的栈状态如下:

adb命令:adb shell dumpsys activity activities

      Application tokens in top down Z order:
      * Task{54bb09b #190 type=standard A=10234:com.xt.client U=0 visible=true visibleRequested=true mode=fullscreen translucent=false sz=4}
        bounds=[0,0][1080,2340]
        * ActivityRecord{75f3f53 u0 com.xt.client/.activitys.test.Test1Activity} t190}
        * ActivityRecord{f91f056 u0 com.xt.client/.activitys.test.Test3Activity} t191}
        * ActivityRecord{777cf91 u0 com.xt.client/.activitys.test.Test2Activity} t190}
        * ActivityRecord{83d9d17 u0 com.xt.client/.activitys.test.Test1Activity} t190}

整个流程如下图所示,Test3跳转Test1的时候,会直接在Test3上面入栈一个新的Test1。所以Task中有4条ActivityRecrod,从下往上的顺序为:Test1,Test2,Test3,Test1。

总结:

首先这里我们就不验证添加参数的类型了。

standard类型的启动方式,是不断的往一个Task栈上面添加新的Activity,哪怕有同样的Activity,也会重新创建一个添加到栈里面。

二.singleInstance类型

为什么把singleInstance拿到前面来说呢?因为后面singleTop类型中的验证会涉及到singleInstance类型的知识点,所以就拿到前面提前来讲了。

官方解释

<!-- Only allow one instance of this activity to ever be
    running.  This activity gets a unique task with only itself running
    in it; if it is ever launched again with the same Intent, then that
    task will be brought forward and its
    {@link android.app.Activity#onNewIntent Activity.onNewIntent()}
    method called.  If this
    activity tries to start a new activity, that new activity will be
    launched in a separate task.  See the
    <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
    Stack</a> document for more details about tasks.-->

翻译后:

只允许一个Activity的实例运行。这个Activity会有唯一的task栈只允许它自身在其中运行,每次被加载的时候都被会把这个栈带到前台,同时会调用Activity的onNewIntent方法进行通知。如果这个Activity尝试去启动一个新的Activity,那么新创建的Activity和当前Activity必须是不同的Task栈。

实验验证

我们仍然是三个Activity,其中Test2Activity设置为singleInstance的模式,

        <activity android:name="com.xt.client.activitys.test.Test1Activity" />
        <activity
            android:name="com.xt.client.activitys.test.Test2Activity"
            android:launchMode="singleInstance" />
        <activity android:name="com.xt.client.activitys.test.Test3Activity" />

设置跳转顺序: Test1->Test2->Test3->Test1->Test2->Test3

执行操作,结果如下,我们可以发现Test2单独占用一个Task

      Application tokens in top down Z order:
      * Task{40cbc68 #196 type=standard A=10234:com.xt.client U=0 visible=true visibleRequested=true mode=fullscreen translucent=false sz=5}
        bounds=[0,0][1080,2340]
        * ActivityRecord{cd9b41f u0 com.xt.client/.activitys.test.Test3Activity} t196}
        * ActivityRecord{9e73f05 u0 com.xt.client/.activitys.test.Test1Activity} t196}
        * ActivityRecord{8fcaaee u0 com.xt.client/.activitys.test.Test3Activity} t196}
        * ActivityRecord{5e3a630 u0 com.xt.client/.activitys.test.Test1Activity} t196}
        * ActivityRecord{9768990 u0 com.xt.client/.MainActivity} t196}
      * Task{17dfc90 #197 type=standard A=10234:com.xt.client U=0 visible=false visibleRequested=false mode=fullscreen translucent=true sz=1}
        bounds=[0,0][1080,2340]
        * ActivityRecord{e147b53 u0 com.xt.client/.activitys.test.Test2Activity} t197}

我们发现区别于第一种类型,这种类型下会有两个Task栈,这两个Task的taskAffinity是一样的。

Test2启动Test3的时候,流程图如下所示。首先前台任务栈从Task2切换到了Task1,Task1中也增加了一条Test3的Activity记录,此时显示在前台的就是Test3了。

总结:

singleInstance类型的启动方式中,

如果不存在包含目标Activity的栈,则创建一个新的Task,这个Task中是目标Activity所独有的,并且只会创建一次,后续如果在启动其它的Activity,这些新的Acitivty属于其parent的task栈。

如果存在包含目标Activity的栈,则直接把包含目标Activity的Task栈挪到前台进行显示。

三.singleTop类型

singleTop相对于startard多了一个复用的概念,就是说某些场景下,会复用已有的Activity而不是每次都新建。

官方解释

        <!-- If, when starting the activity, there is already an
            instance of the same activity class in the foreground that is
            interacting with the user, then
            re-use that instance.  This existing instance will receive a call to
            {@link android.app.Activity#onNewIntent Activity.onNewIntent()} with
            the new Intent that is being started. -->

翻译后:

在启动Activity的时候,如果前台中存在一个相同Activity类的实例与用户交互,则直接使用这个实例。这个存在的实例在启动的时候会通过onNewIntent方法收到通知。

实验验证

这里为了体现singleTop的作用,我们做一个对比实验。

首先,我们设置Test3为singleInstance模式,其他的都是默认的standard模式。

        <activity android:name="com.xt.client.activitys.test.Test1Activity" />
        <activity android:name="com.xt.client.activitys.test.Test2Activity" />
        <activity
            android:name="com.xt.client.activitys.test.Test3Activity"
            android:launchMode="singleInstance" />

然后设置跳转顺序:Test1->Test2->Test3->Test2

结果如下:

      Application tokens in top down Z order:
      * Task{54bb09b #190 type=standard A=10234:com.xt.client U=0 visible=true visibleRequested=true mode=fullscreen translucent=false sz=4}
        bounds=[0,0][1080,2340]
        * ActivityRecord{75f3f53 u0 com.xt.client/.activitys.test.Test2Activity} t190}
        * ActivityRecord{777cf91 u0 com.xt.client/.activitys.test.Test2Activity} t190}
        * ActivityRecord{83d9d17 u0 com.xt.client/.activitys.test.Test1Activity} t190}
        * ActivityRecord{6979f3f u0 com.xt.client/.MainActivity} t190}
      * Task{e1b8d7 #191 type=standard A=10234:com.xt.client U=0 visible=false visibleRequested=false mode=fullscreen translucent=true sz=1}
        bounds=[0,0][1080,2340]
        * ActivityRecord{f91f056 u0 com.xt.client/.activitys.test.Test3Activity} t191}

我们可以看到有两个Task栈,Task1中有3个Activity记录,分别是Test1,Test2,Test2。而Task2中则只有一个Test3的记录。

此时,我们做一个改动,把Test2设置为singleTop类型,如下:

        <activity android:name="com.xt.client.activitys.test.Test1Activity" />
        <activity android:name="com.xt.client.activitys.test.Test2Activity"
            android:launchMode="singleTop" />
        <activity
            android:name="com.xt.client.activitys.test.Test3Activity"
            android:launchMode="singleInstance" />

同样的跳转顺序:Test1->Test2->Test3->Test2

结果如下:

      Application tokens in top down Z order:
      * Task{54bb09b #190 type=standard A=10234:com.xt.client U=0 visible=true visibleRequested=true mode=fullscreen translucent=false sz=4}
        bounds=[0,0][1080,2340]
        * ActivityRecord{777cf91 u0 com.xt.client/.activitys.test.Test2Activity} t190}
        * ActivityRecord{83d9d17 u0 com.xt.client/.activitys.test.Test1Activity} t190}
      * Task{e1b8d7 #191 type=standard A=10234:com.xt.client U=0 visible=false visibleRequested=false mode=fullscreen translucent=true sz=1}
        bounds=[0,0][1080,2340]
        * ActivityRecord{f91f056 u0 com.xt.client/.activitys.test.Test3Activity} t191}

我们发现,只有Task2仍然只有一条Test3的记录,但是Task1中,只有两条记录了,分别为Test1和Test2。相对于上一次实验,这次少了一个Test2的记录。

Test3跳转Test2的流程图如下,前台任务栈从Task1切换到了Task2,并且Test2没有新建,而是直接复用栈顶的实例对象。

总结:

总结一下,singleTop类型的启动方式,当从别的Task任务栈切换回当前任务栈时,如果栈顶实例就是同样的Activity,则直接进行复用,并且通过onNewIntent方法进行通知。

四.singleTask类型

singleTask类型其实就是singleTop类型的增强版,我们来看下他们的区别。

官方解释

        <!-- If, when starting the activity, there is already a task running
            that starts with this activity, then instead of starting a new
            instance the current task is brought to the front.  The existing
            instance will receive a call to {@link android.app.Activity#onNewIntent
            Activity.onNewIntent()}
            with the new Intent that is being started, and with the
            {@link android.content.Intent#FLAG_ACTIVITY_BROUGHT_TO_FRONT
            Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT} flag set.  This is a superset
            of the singleTop mode, where if there is already an instance
            of the activity being started at the top of the stack, it will
            receive the Intent as described there (without the
            FLAG_ACTIVITY_BROUGHT_TO_FRONT flag set).  See the
            <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
            Stack</a> document for more details about tasks.-->

翻译后:

在启动Activity的时候,如果栈中存在一个这样的Activity,会通过在当前栈中把Activity对象带到前台的方式来替代新创建一个对象。启动的时候那个已存在的实例对象中onNewIntent方法会收到通知,并且会有Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT的标记。这是singleTop类型的扩展,如果目标Activity就处于栈顶部,则不会有FLAG_ACTIVITY_BROUGHT_TO_FRONT标记。

实验验证

我们采取和singeTop类似的方式,仍然进行对比实验。

仍然是三个Activity,其中Test1Activity设置为singleTask的模式,如下:

        <activity android:name="com.xt.client.activitys.test.Test1Activity" />
        <activity android:name="com.xt.client.activitys.test.Test2Activity" />
        <activity android:name="com.xt.client.activitys.test.Test3Activity"
            android:launchMode="singleInstance" />

区别于singeTop中的方式,我们这里设置Test3跳转回Test1。

设置如下跳转顺序:Test1->Test2->Test3->Test1

进行操作,使用adb命令捕获栈结构如下:

      Application tokens in top down Z order:
      * Task{d44dd11 #198 type=standard A=10234:com.xt.client U=0 visible=true visibleRequested=true mode=fullscreen translucent=false sz=4}
        bounds=[0,0][1080,2340]
        * ActivityRecord{5902bb5 u0 com.xt.client/.activitys.test.Test1Activity} t198}
        * ActivityRecord{46c4832 u0 com.xt.client/.activitys.test.Test2Activity} t198}
        * ActivityRecord{6e48322 u0 com.xt.client/.activitys.test.Test1Activity} t198}
      * Task{9bdbdf4 #199 type=standard A=10234:com.xt.client U=0 visible=false visibleRequested=false mode=fullscreen translucent=true sz=1}
        bounds=[0,0][1080,2340]
        * ActivityRecord{f0693c7 u0 com.xt.client/.activitys.test.Test3Activity} t199}

Task1中有Test1,Test2,Test1三条记录,Task2中只有Test3一条记录。

我们再把Test1改为singleTask类型,如下:

        <activity android:name="com.xt.client.activitys.test.Test1Activity" 
            android:launchMode="singleTask" />
        <activity android:name="com.xt.client.activitys.test.Test2Activity" />
        <activity android:name="com.xt.client.activitys.test.Test3Activity"
            android:launchMode="singleInstance" />

同样的跳转顺序:Test1->Test2->Test3->Test1,再次进行实验,结果如下:

      Application tokens in top down Z order:
      * Task{9de4b6a #200 type=standard A=10234:com.xt.client U=0 visible=true visibleRequested=true mode=fullscreen translucent=false sz=2}
        bounds=[0,0][1080,2340]
        * ActivityRecord{4bdcfd7 u0 com.xt.client/.activitys.test.Test1Activity} t200}
      * Task{af6f1f0 #201 type=standard A=10234:com.xt.client U=0 visible=false visibleRequested=false mode=fullscreen translucent=true sz=1}
        bounds=[0,0][1080,2340]
        * ActivityRecord{66c6a33 u0 com.xt.client/.activitys.test.Test3Activity} t201}

这时候我们发现区别于上一个实验,这时Task1中只有一条Test1的记录了。

整个流程如下图所示,Test3中启动Test1的时候,前台任务栈从Task2切换到Task1,并且直接把Task1中Test2记录进行出栈操作,此时显示在前台的就是Test1了。

总结:

使用singleTask类型后,如果发现目标任务栈Task中存在相同的Activity实例时,则会出栈该实例上面的所有其它类型的实例,从而让该实例展示到前台。

六.singleInstancePerTask

singleInstancePerTask由其名可知,是singleInstance类型的增强版,其实在我看来,更像是singleInstance和singleTask的结合体,接下来我们来看下区别。

官方解释

<!-- The activity can only be running as the root activity of the task, the first activity
    that created the task, and therefore there will only be one instance of this activity
    in a task. In constrast to the {@code singleTask} launch mode, this activity can be
    started in multiple instances in different tasks if the
    {@code FLAG_ACTIVITY_MULTIPLE_TASK} or {@code FLAG_ACTIVITY_NEW_DOCUMENT} is set.-->

翻译后:

Activity只能作为Task栈的根结点(第一个被创建)运行,因此栈中只可能有一个该Activity的实例。对比singleTask类型,如果设置了FLAG_ACTIVITY_MULTIPLE_TASK标记该Activity可以在不同的栈生成多个不同的实例。

实验验证

设置三个Activity,其中Test3Activity设置为singleInstancePerTask的模式,如下:

<activity android:name="com.xt.client.activitys.test.Test1Activity" />
<activity android:name="com.xt.client.activitys.test.Test2Activity" />
<activity
    android:name="com.xt.client.activitys.test.Test3Activity"
    android:launchMode="singleInstancePerTask" />

设置如下跳转顺序:Test1->Test2->Test3->Test1->Test2->Test3->Test1

进行操作,使用adb命令捕获栈结构如下:

      Application tokens in top down Z order:
      * Task{e77ae1e #206 type=standard A=10234:com.xt.client U=0 visible=true visibleRequested=true mode=fullscreen translucent=false sz=2}
        bounds=[0,0][1080,2340]
        * ActivityRecord{a818f11 u0 com.xt.client/.activitys.test.Test1Activity} t206}
        * ActivityRecord{632e259 u0 com.xt.client/.activitys.test.Test3Activity} t206}
      * Task{6ef6ec0 #205 type=standard A=10234:com.xt.client U=0 visible=false visibleRequested=false mode=fullscreen translucent=true sz=3}
        bounds=[0,0][1080,2340]
        * ActivityRecord{9918e35 u0 com.xt.client/.activitys.test.Test2Activity} t205}
        * ActivityRecord{25df40c u0 com.xt.client/.activitys.test.Test1Activity} t205}

可以看到,虽然启动了两次Test3,但是仍然只有两个Task栈,可以证明singleInstancePerTask类型是栈单例的,一个被声明的Activity只会拥有唯一的一个栈(不设置标记的前提下)。

如下图所示,区别于singleInstance类型的是,在这个归属Test3的栈中,是可以放入其它的Activity的,比如这里的Test1。

总结

singleInstancePerTask类型的启动方式中,

如果不存在包含目标Activity的栈,则创建一个新的Task,这个Task中是目标Activity所独有的,并且只会创建一次,后续如果在启动其它的Activity,这些新的Acitivty仍然当前的task栈。

如果存在包含目标Activity的栈,则把包含目标Activity的Task栈挪到前台,并且把该栈中目标Activity上面的所有Activity进行出栈操作,从而实现目标Activity显示在前台的效果。

当然,如官方文档所描述,如果启动singleInstancePerTask类型的Activity时,同时设置FLAG_ACTIVITY_MULTIPLE_TASK标记,应该是可以启动多个包含目标Activity的Task栈的,这里就不做实验了。

扩展性问题:

问题1:如果一个Task中的Activity全部出栈,会退到哪里?

答:假设Task1启动了Task2,那么Task2中的Activity如果全部出栈,就会把Task1推到前台,Task1中栈顶的Activity就会被显示。

我们以singleInstance类型中的流程为例,假设启动流程如下:

MainActivity(Task1)->Test1(Task2)->Test2(Task2)->Test3(Task3)->Test1(Task2)->Test2(Task3)->Test3(Task2)。

最终Test3属于Task2的栈,所以Task2中的4个Activity记录全部出栈后,会返回Task1的MainActivity,而不是Test2。

问题2:如何区分是首次创建还是从栈中返回的?

答:这个注释中就告诉我们了,栈中复用的回调用onNewIntent方法。

问题3:如何区分是从栈顶复用还是栈中复用的?

答:首先解释下栈顶复用还是栈中复用。如下图所示,如果启动的是Test3,就是栈顶复用,如果启动的是Test2或者Test1,那么就是栈中复用。

这个其实官方文档的注释中也告诉我们结果了,如果是栈中复用,则onNewIntent方法中,其flags参数中会包含Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT标记,可以通过这个来区别。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/188104.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【金三银四系列】之MySql面试突击(2023版)

Mysql金三银四面试突击班 1.Bin log是什么&#xff0c;有什么用&#xff1f;&#xff08;数据库被人干掉了怎么办&#xff1f;&#xff09; 1.bin Log: 数据恢复 主从复制 MySQL Server 层也有一个日志文件&#xff0c;叫做 binlog&#xff0c;它可以被所有的存储引擎使用。…

PRD-产品需求说明文档

产品需求说明文档&#xff08;PRD&#xff09;可以将产品设计思路清晰的展现给团队人员&#xff0c;便于他们快速理解产品。产品需求说明文档如何写呢&#xff1f;本文希望能够得到高人指点&#xff0c;本人是小白&#xff0c;同时不建议其他小白参考此文以免造成干扰。 包括文…

Spark 学习案例

案例1&#xff1a;搜索引擎日志分析 数据来源&#xff1a;使用搜狗实验室提供的【用户查询日志】数据。使用Saprk框架&#xff0c;将数据封装到RDD中进行数据处理分析。 数据网址&#xff1a;数据地址 这个地址可能过期了&#xff0c;需要的伙伴可以私聊博主。 数据格式&…

css清除浮动的方法

浮动的盒子会脱离标准流&#xff0c;不占有自己原先的位置&#xff0c;导致下面的其他标签往上移动 此时&#xff0c;可以给浮动的盒子添加一个父盒子&#xff08;块级&#xff09;&#xff0c;并设置高度&#xff0c;就可以避免下面的其他标签上浮 但是有时候父盒子不能设置高…

pycharm:新建虚拟环境和安装依赖

前言 小编深有体会&#xff0c;在刚开始用pycharm跑python的项目的时候&#xff0c;一时间不知道如何下手&#xff0c;特别是作为一个新手小白&#xff0c;这里总结了一份新手避坑指南&#xff0c;主要是新建虚拟环境&#xff08;生成一个项目对应的解释器&#xff09;以及安装…

温度预测 python | 使用 Python 可以使用机器学习模型进行温度预测

使用 Python 可以使用机器学习模型进行温度预测。常用的模型有回归分析、随机森林等。使用前需要准备足够的历史数据并进行特征工程&#xff0c;构建模型并进行训练&#xff0c;最后使用预测结果。 文章目录温度预测 回归分析导入必要的库&#xff1a;读取温度数据&#xff1a;…

Java中的插入排序和希尔排序

插入排序&&希尔排序插入排序希尔排序上一篇博客我给大家伙说了一下子堆排序,之所以我把插入排序和希尔排序放在一起呢,是因为希尔排序实际上用到了插入排序的思想,希望下面的内容能够帮助到大家.对于插入排序呢,我们可以参考抓牌顺牌,就在一般情况下,我们也不考虑什么组…

对象在Eden区分配

一、对象在Eden区分配大多数情况下&#xff0c;对象在新生代中 Eden 区分配。当 Eden 区没有足够空间进行分配时&#xff0c;虚拟机将发起一次Minor GC。在测试之前我们先来看看 Minor GC和Full GC 有什么不同呢&#xff1f;Minor GC/Young GC&#xff1a;指发生新生代的的垃圾…

oracle11g SAP测试机归档日志暴增排查(二)

接上面一的内容&#xff0c;通过logminer可以知道是因为oracle11g设置awr快照引起的插入数据&#xff0c;所以要看这个插入是否正常。 之前也发现SYSAUX表空间也没有多少了&#xff0c;应该这个原因引起产生大量的日志 6、查找SYSAUX表空间满的原因 对于SYSAUX表空间而言&…

【博学谷学习记录】大数据课程-学习第五周总结

Hadoop概述 Hadoop介绍 Hadoop是Apache旗下的一个用java语言实现开源软件框架&#xff0c;是一个开发和运行处理大规模数据的软件平台。允许使用简单的编程模型在大量计算机集群上对大型数据集进行分布式处理。 狭义上说&#xff0c;Hadoop指Apache这款开源框架&#xff0c;它…

Gateway, Zuul, Oauth2.0, 前后端分离, 定制页面,登录回调接口的处理

由于公司与Alexa平台接入了语音控制的功能&#xff0c;需要将公司的账号与Alexa的账号进行绑定&#xff0c;所以需要账号授权的操作&#xff0c;也就是使用授权码模式。开发过程中遇到了很多坑&#xff0c;网上关于前后端分离的定制页面的介绍又很少&#xff0c;前前后后花了一…

泰拉瑞亚灾厄NPC不复活x哥布林军队入侵中断

文章首发及后续更新&#xff1a;https://mwhls.top/4415.html&#xff0c;无图/无目录/格式错误/更多相关请至首发页查看。 新的更新内容请到mwhls.top查看。 欢迎提出任何疑问及批评&#xff0c;非常感谢&#xff01; 目录 NPC 不复活 原因 解决办法 哥布林军队入侵中断 说…

2019-ICML-Towards Graph Pooling by Edge Contraction

2019-ICML-Towards Graph Pooling by Edge Contraction Paper: https://graphreason.github.io/papers/17.pdf Code: https://github.com/Jiajia43/pytorch_geometric 通过边收缩实现图池化 池化层可以使GNN对抽象的节点组而不是单个节点进行推理&#xff0c;从而增加其泛化潜…

MongoDB下载安装

MongoDB 是一个基于分布式文件存储的数据库。由 C 语言编写&#xff0c;旨在为 WEB 应用提供可扩展的高性能数据存储解决方案。 MongoDB 是一个介于关系数据库和非关系数据库之间的产品&#xff0c;是非关系数据库当中功能最丰富&#xff0c;最像关系数据库的。 &#xff08;摘…

音频编辑服务UI SDK接入指导及常见问题

华为 HMS Core 音频编辑服务&#xff08;Audio Editor Kit&#xff09;是华为帮助全球开发者快速构建各类应用音频能力的服务&#xff0c;汇聚了华为在音乐、语音等相关音频领域的先进技术。音频编辑服务为开发者们提供音频基础编辑、AI配音、音源分离、空间渲染、变声、多种音…

IT自动化运维体系的搭建

大家好&#xff0c;我是技福的小咖老师。 对于构建IT运维管理系统而言&#xff0c;如何使用系统的方法来改善运维服务&#xff0c;以及对运维过程进行全面审查尤为重要。今天我们就来讲讲IT自动化运维体系的搭建。 设立IT运维优先原则 优先处理原则是指定义出IT运维的每个关键…

JAVA工具-JDK、JRE、JVM、JIT

目录 概要 JDK和JRE区别 JAVA工具间的联系 JAVA源代码如何被操作系统执行 补充:JIT 概要 JDK&#xff1a;Java Developers Kit-Java开发工具 JRE&#xff1a;Java Runtime Environment-Java运行环境 JVM&#xff1a;Java Virtual Machine-Java虚拟机 JIT&#xff1a;J…

阿里的又一款数据高效同步工具DataX,真香!

我们公司有个项目的数据量高达五千万&#xff0c;但是因为报表那块数据不太准确&#xff0c;业务库和报表库又是跨库操作&#xff0c;所以并不能使用 SQL 来进行同步。当时的打算是通过 mysqldump 或者存储的方式来进行同步&#xff0c;但是尝试后发现这些方案都不切实际&#…

MySQL的回表

核心问题 什么是回表&#xff1f; 答&#xff1a; 回表是一个过程&#xff0c;是获取到主键后再通过主键去查询数据的一个过程就叫回表。 那这个主键从哪来&#xff1f; 从叶子结点存储的内容来&#xff0c;如果存储的是非聚簇索引则通过叶子节点存储的值获取&#xff0c;该值…

机器学习笔记之生成对抗网络(一)逻辑介绍

机器学习笔记之生成对抗网络——逻辑介绍引言生成对抗网络——示例生成对抗网络——数学语言描述生成对抗网络——判别过程描述引言 本节将介绍生成对抗网络的基本逻辑与数学语言描述。 生成对抗网络——示例 生成对抗网络(Generative Adversarial Networks,GAN)&#xff0c…