APP启动方式分析——冷启动、热启动、温启动

编程知识 更新时间:2023-05-02 19:13:02

APP启动分析

Cold start

At the beginning of a cold start, the system has three tasks. These tasks are:

1、Loading and launching the app.
2、Displaying a blank starting window for the app immediately after launch
3、.Creating the app process.

As soon as the system creates the app process, the app process is responsible for the next stages:

1、Creating the app object.
2、Launching the main thread.
3、Creating the main activity.
4、Inflating views.
5、Laying out the screen.
6、Performing the initial draw.

系统和应用之间交互简图

Application creation

When your application launches, the blank starting window remains on the screen until the system finishes drawing the app for the first time. At that point, the system process swaps out the starting window for your app, allowing the user to start interacting with the app.
If you’ve overloaded Application.onCreate() in your own app, the system invokes the onCreate() method on your app object. Afterwards, the app spawns the main thread, also known as the UI thread, and tasks it with creating your main activity.

From this point, system- and app-level processes proceed in accordance with the app lifecycle stages.

Activity creation

After the app process creates your activity, the activity performs the following operations:

1、Initializes values.
2、Calls constructors.
3、Calls the callback method, such as Activity.onCreate(), appropriate to the current lifecycle state of the activity.

Typically, the onCreate() method has the greatest impact on load time, because it performs the work with the highest overhead: loading and inflating views, and initializing the objects needed for the activity to run.

Hot start

A hot start of your application is much simpler and lower-overhead than a cold start. In a hot start, all the system does is bring your activity to the foreground. If all of your application’s activities are still resident in memory, then the app can avoid having to repeat object initialization, layout inflation, and rendering.However, if some memory has been purged in response to memory trimming events, such as onTrimMemory(), then those objects will need to be recreated in response to the hot start event.
A hot start displays the same on-screen behavior as a cold start scenario: The system process displays a blank screen until the app has finished rendering the activity.

Warm start

A warm start encompasses some subset of the operations that take place during a cold start; at the same time, it represents more overhead than a hot start. There are many potential states that could be considered warm starts.
For instance:

  • The user backs out of your app, but then re-launches it. The process may have continued to run, but the app must recreate the activity from scratch via a call to onCreate().
  • The system evicts your app from memory, and then the user re-launches it. The process and the activity need to be restarted, but the task can benefit somewhat from the saved instance state bundle passed into onCreate().

译文

冷启动

简单讲app冷启动可以分为两个阶段
第一阶段

1、加载并启动app
2、启动后立即显示一个空白的启动窗口
3、创建app进程

第二阶段

1、创建app对象
2、启动主进程
3、创建MainActivity
4、渲染视图
5、执行onLayout
6、执行onDraw

应用创建
当应用程序启动时,空白的开始窗口将保留在屏幕上,直到系统第一次绘制完应用程序。此时,系统进程会为应用程序交换启动窗口,允许用户开始与应用程序交互

之后按照app生命周期依次执行

简单说就是当屏幕上的组件渲染结束后,用app窗口替换系统空白窗口,此时允许用户与app进行交互

Activity创建

1、初始化values
2、初始化构造方法
3、执行生命周期回调

热启动

热启动时,系统将activity放到前台。如果应用程序的所有activity存在内存中,则应用程序可以避免重复对象初始化、渲染、绘制操作。

如果由于内存不足导致对象被回收,则需要在热启动时重建对象,此时与冷启动时将界面显示到手机屏幕上一样。

温启动

温启动时由于app的进程仍然存在,只执行冷启动第二阶段流程

1、创建app对象
2、启动主进程
3、创建MainActivity
4、渲染视图
5、执行onLayout
6、执行onDraw

温启动常见场景:

1、用户双击返回键退出应用
2、app由于内存不足被回收

更多推荐

APP启动方式分析——冷启动、热启动、温启动

本文发布于:2023-04-28 05:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/f1b38616927f5f83e15ec23ef14598ba.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   冷启动   APP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 107804文章数
  • 27248阅读数
  • 0评论数