Android launch optimization

First, start classification

Android starting points cold start, hot start, warm start.
1. Cold start: When starting the application, a background process without this application, you need to create a new process.

Cold start:

click (click on the application icon) -> ipc -> Process.Start -> ActivityThread
-> bindApplication -> LifeCycle -> ViewRootImpl

2, Hot start: there is a background process that is currently applied (such as pressing the Home key to exit the application),
click to open the application again, this process does not need to create a process, do not need to initialize the application, you do not need to initialize activity.

3, warm start: application process is still, probably due to lack of system memory, activity was recovered, need to initialize activity.

Can be seen from the above process, a cold start is relatively time consuming to start the tuning process is basically done for the cold start. To optimize the place from the first operation to create the Application screen layout activity to show.
Summary:
1, in the Application oncreate Do not do time-consuming operation.
2, application of asynchronous initialization must initialize the various tripartite SDK and so on.
3, application initialization delay in re-initialize the place needs to be done to use the tripartite SDK and so on.
4, the first screen activity not to do time-consuming operation oncreate, try to put the sub-thread processing.

Second, the measure start-up time

Start time measurement method, there are two:
. 1, the adb command
characteristics: easy to operate

adb shell am start -W packagename/首屏activity
例如:adb shell am start -W com.pursue.demo/com.pursue.demo.ui.flash.FlashActivity

Export

2, manual dot:
Start Buried start, a starting completion point whichever buried difference.

AttachBaseContext calculation start time in the method of application (by the method executed before oncreate attachBaseContext method), the end time is the first screen activty Feed first display data. Eg:
start time:
Here Insert Picture DescriptionEnd time:
Here Insert Picture Descriptiontwo measures comparison:
the adb: the line more convenient to use, but not to the online
manual dot: can be taken online, RBI will take to upload data to the server.

Summary: RBI is recommended to use the manual mode, because many Android models, need to be concerned about the application on the user to start the phone.

Published 29 original articles · won praise 8 · views 10000 +

Guess you like

Origin blog.csdn.net/sushineboy/article/details/104452861