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

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由于内存不足被回收

  • 4
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值