These days I talked about the startup page optimization problem, which is a platitude.

1. Startup mode of App:

A, cold start; The application is killed and no corresponding process is started in the background

B. Hot start; An application process starts in the background

We need to optimize the startup page, mainly for cold startup.

During cold startup our application executes like this:

As can be seen from the above figure, if we want to optimize the startup speed, we should focus on reducing the main thread time on Application and Acitivity startup to achieve the optimization purpose.

2. White screen and black screen during startup

The style that sets the theme to start the Activity contains windowBackground, which will be loaded when the Activity is started in onCreate, and sets the background image for the Window

The code Settings are as follows:

But often we like this set, is the background show special long, in other words we just solve the problem of white and black screen, but nature didn’t solve the problem of start time long, but this kind of practice in space for time also can yet be regarded as a kind of solution, at least let user starts when you can see a interface.

3. Startup time analysis:

A, SDK initialization time, here we need to measure the time of each SDK initialization to see how much time it takes. Another APP often integrates multiple SDKS, do not ignore the small amount, for example, an SDK takes 100ms on average. If it integrates 10 SDKS, it takes 1s, which is quite a long time.

B. Miscellaneous business; The main point here is that after cold startup, all kinds of pop-ups, all kinds of pop-ups together bring drawing lag is very obvious, so at this time it is best to prioritize this kind of business.

C. Network determination; For example, when the app is cold launched, we have to ask the network to see if there are any advertising materials, and the next step of the app is determined by the result. This is very slow. Even more exaggerated, some ads are video ads, which leads to at least 10s of time for users to cold start the app. Of course in addition to boot advertising, combined with business needs we have a variety of network to determine the process; We can obtain the data needed for the next network confirmation this time, so that the next cold startup application does not need to wait for the network confirmation and directly enter the next step

4, summarize

Prioritize the business SDK that hinders startup optimization, and participate in delay processing for those unimportant business SDK. For example, we can make reasonable use of Idle mechanism in Looper to put some unimportant things into Idle processing.

We need to sort out the operation of the main thread in the startup process, time the SDK initialization, prioritize the business, and make reasonable use of local files and memory cache to avoid multiple network confirmations. Do not initialize in advance or request services that are not available temporarily; Services that can be handled outside the main thread are handled in child threads, freeing up more time and space for the main thread.