Android cold start optimization method
By optimizing the Application class and Activity page logic of Android App, the problem of excessive cold start taking too long is solved, and the cold start "on instant" function is realized, which improves the user experience.
Patent Information
- Application Number
- CN202510198081.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-21
- Publication Date
- 2025-06-27
Smart Images

Figure CN120216050A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of Android cold start optimization, and it is an Android cold start optimization method. Background Art
[0002] When an Android App is in a closed state on the application desktop, from clicking the icon to fully displaying the home page content, if created according to normal Android code and business logic code executed, it will be very time-consuming. Especially after the business becomes more and more complex, the execution time of business-related code will increase, thus increasing the cold start time; after an Android Activity is created, loading complex xml files is time-consuming, which will also increase the cold start time.
[0003] However, in the prior art, there are many deficiencies in the startup process of the original App: First, there is no clear priority for initializing the SDK in the Application, resulting in unnecessary initialization processes affecting the cold start time; then, in the splash screen page SplashActivity, the system takes time to parse the xml layout. Whether an advertisement is displayed or not, xml parsing has to be performed, and the remaining initialization operations after authorization are all executed in this class. After execution, it jumps to the home page, increasing the cold start time; finally, the creation of the home page has no priority, resulting in the creation of non-visible pages, increasing the cold start time. Summary of the Invention
[0004] The present invention provides an Android cold start optimization method to solve the technical problems that there is no clear priority for initializing the SDK in the Application, resulting in unnecessary initialization processes affecting the cold start time; then, in the splash screen page SplashActivity, the system takes time to parse the xml layout. Whether an advertisement is displayed or not, xml parsing has to be performed, and the remaining initialization operations after authorization are all executed in this class. After execution, it jumps to the home page, increasing the cold start time; finally, the creation of the home page has no priority, resulting in the creation of non-visible pages, increasing the cold start time.
[0005] The present invention solves the above technical problems through the following technical solutions:
[0006] The present invention provides an Android cold start optimization method, and the Android cold start optimization method includes the following steps:
[0007] S1. Split and optimize all business logic codes of the Application class, remove unnecessary codes after retaining necessary initializations;
[0008] S2. Delete all logics of the first Activity page, only retain the basic jump function, and set the background to be transparent;
[0009] S3. Home Activity optimization.
[0010] Furthermore, the Application process logic in step (S1) is in the AttachBaseContext method to initialize necessary content: initialize MMKV storage and initialize the SharedPreferences class of the App.
[0011] Furthermore, the Application process logic in step (S1) is in the onCreate method to initialize Alibaba Router Arouter, initialize the business base class and utility class, and then start the splash screen class LogoSplashActivity.
[0012] Furthermore, the method for optimizing the home Activity in step (S3) specifically includes the following steps: a. Prioritize the display of the ad splash screen content. Under the ad page, perform the initialization and creation operation of the current page of the main Activity, including loading cached data to display the UI page.
[0013] b. After the creation of the current page of the main Activity is completed, first remove the ad splash screen page, and at the same time initialize and create non-current pages. Then, according to the code priority, initialize each SDK and perform data acquisition operations.
[0014] Furthermore, before the original function of the LogoSplashActivity process logic in step (S2) was modified, the ad display and jump processing functions were executed here. Since parsing the ad layout in xml was time-consuming, all ad logics on the splash screen page were removed here, and the page was set to be transparent. In this way, the time consumption in the splash screen page was reduced from the original statistical 1000ms+ to about 100ms.
[0015] Furthermore, the MainActivity process logic in step (S2) includes:
[0016] (1) In setContentView, prioritize the display of the ad splash screen page, and then in initBaseData, start to process the logic of the home page.
[0017] (2) When installing the App for the first time, an authorization pop-up window will be displayed. After agreeing to the authorization, the method InitAppUtils.initWithAgree will be executed. Inside this method, there are the methods initDataWithAgree and initSDKWithAgree. As the names suggest, the initDataWithAgree method is used to obtain business data and cached data, and the initSDKWithAgree method is used to initialize the SDK. Inside the method, a thread pool logic is added to solve the time-consuming problem asynchronously;
[0018] (3) For the cold start of the second + and above, there is no authorization pop-up window or advertisement. It will execute sequentially according to the InitAppUtils.initWithAgree method in (2). After continuing with the InitAppUtils.initWithAgree method in (2), the initMain method will be executed. This method is used to create the visible home page content. After executing initMain, the hideAndLateInit method needs to be executed to display the home page content;
[0019] (4) When there is an advertisement during the cold start of the second + and above, the showAd will be executed to display the advertisement logic while the initMain method is being executed. After the advertisement execution is completed, the hideAndLateInit method will be executed to perform advertisement removal and subsequent initialization work. See the method initByLowProperty; The initByLowProperty method integrates a thread pool and the loading priority sequence to achieve both the "instant start" function and avoid congestion and jamming.
[0020] Furthermore, in the step (S1), Application is the base class of the Android application. It provides the life cycle management of the application and the overall application context environment. Application is an abstract class, and usually, a custom application class needs to be created by inheriting and implementing its abstract methods.
[0021] Furthermore, in the step (S3), Activity is a user interface. It displays various UI elements by loading a specified layout file and simultaneously processes the interaction events of these UI elements, such as clicks and text input. Different Activities can be jumped to, connecting different pages to jointly complete a specific operation process.
[0022] Further, the setContentView is a very important method in Android development. It is used to set the layout for the current Activity. The setContentView method is usually called in the onCreate method of the Activity to specify the layout to be displayed by this Activity.
[0023] Further, the initBaseData method is usually a custom method for initializing the base class data in Android application development, especially when using the Activity base class encapsulation. The initBaseData method is an abstract method or a specific implementation method defined in the Activity base class, and is used to initialize some global or shared data when the Activity is created.
[0024] Based on common general knowledge in the art, the above preferred conditions can be combined arbitrarily to obtain various preferred embodiments of the present invention.
[0025] The positive and progressive effects of the present invention are as follows:
[0026] The proposed Android cold start optimization method combines the methods of asynchronous loading with a thread pool, preferentially using cache for the home page display, delaying the creation of non-home pages, delaying the loading of non-core SDKs, and setting the priority order for loading, achieving "instant start" for cold start, and optimizing the time-consuming from 4 seconds to 0.5 seconds for starting to the home page, greatly improving the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the present application.
[0028] Figure 1 It is a flowchart of the Android cold start optimization method of the present invention.
[0029] Figure 2 It is a complete process schematic diagram from Application to MainActivity of the Android cold start optimization method of the present invention.
[0030] Figure 3 It is a schematic diagram of the creation process of MainActivity of the Android cold start optimization method of the present invention.
[0031] Figure 4 It is a schematic diagram of the initialization priority of the Android cold start optimization method of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0032] In order to enable those skilled in the art of this technology to better understand the solution of this application, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of this application. Obviously, the described embodiments are only a part of the embodiments of this application, rather than all the embodiments. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the scope of protection of this application.
[0033] It should be noted that, without conflict, the embodiments in this application and the features in the embodiments may be combined with each other.
[0034] Embodiment:
[0035] As Figures 1-4 shown, the Android cold start optimization method includes the following steps:
[0036] S1. Split and optimize all business logic codes of the Application class, remove unnecessary codes after retaining necessary initializations;
[0037] S2. Delete all logics of the first Activity page, only retain the basic jump function, and set the background to be transparent;
[0038] S3. Optimize the main page Activity.
[0039] Further, the Application process logic in step (S1) is in the AttachBaseContext method to initialize necessary contents: initialize mmkv storage, and initialize the SharedPreferences class of the App.
[0040] Further, as Figure 2 shown, the Application process logic in step (S1) is in the onCreate method to initialize Arouter of Alibaba, initialize the business base class and the utility class, and then start the splash screen class LogoSplashActivity.
[0041] Further, the method for optimizing the main page Activity in step (S3) specifically includes the following steps: a. Prioritize the display of the advertisement splash screen content. Under the advertisement page, perform the initialization and creation operation of the current page of the main Activity, including loading cached data to display the UI page;
[0042] b. After the creation of the current page of the main Activity is completed, first remove the advertisement splash screen page, and at the same time initialize and create non-current pages, and then initialize each SDK and perform data acquisition operations according to the code priority.
[0043] Further, before the original function of the LogoSplashActivity process logic in step (S2) was modified, the advertisement display and jump processing functions were executed here. Since the xml parsing of the advertisement layout was time-consuming, all advertisement logics on the splash screen were removed here, and the page was set to be transparent. In this way, the time consumption in the splash screen was reduced from the original statistical 1000ms+ to about 100ms.
[0044] Further, referring to Figure 3 and Figure 4 , the MainActivity process logic in step (S2) includes:
[0045] (1) In setContentView, the advertisement splash screen is preferentially displayed, and then in initBaseData, the logic of the home page is started to be processed;
[0046] (2) When the App is installed for the first time, an authorization pop-up window will be executed. After the authorization is agreed, the method InitAppUtils.initWithAgree will be executed. The method internally contains the methods initDataWithAgree and initSDKWithAgree. As can be known from the names, the initDataWithAgree method is to obtain business data and cached data, and the initSDKWithAgree method is to initialize the SDK. Inside the method, a thread pool logic is added to solve the time-consuming problem asynchronously;
[0047] (3) For the second+ cold start without an authorization pop-up window and no advertisement, it will be executed in sequence according to the InitAppUtils.initWithAgree method in (2). After continuing the InitAppUtils.initWithAgree method in (2), the initMain method will be executed. This method is used to create the visible home page content (, and after executing initMain, the hideAndLateInit method will be executed to display the home page content;
[0048] (4) When there is an advertisement for the second+ cold start, the showAd will be executed to display the advertisement logic while the initMain method is being executed. After the advertisement execution is completed, the hideAndLateInit method will be executed to perform advertisement removal and subsequent initialization work. See the method initByLowProperty; the initByLowProperty method integrates a thread pool and the loading priority sequence, so as to achieve both the "instant start" function and no congestion or card.
[0049] Further, in the step (S1), Application is the base class of Android application programs. It provides the life cycle management of application programs and the overall application context environment. Application is an abstract class, and usually a custom application class needs to be created by inheriting and implementing its abstract methods.
[0050] Further, in the step (S3), Activity is a user interface that displays various UI elements by loading a specified layout file and simultaneously processes the interaction events of these UI elements, such as clicks and text input. Different Activities can be jumped to, connecting different pages to jointly complete a specific operation process.
[0051] Further, the setContentView is a very important method in Android development. It is used to set the layout for the current Activity. The setContentView method is usually called in the onCreate method of the Activity to specify the layout to be displayed by this Activity.
[0052] Further, the initBaseData method is usually a custom method for initializing base class data in Android application development, especially when using the Activity base class encapsulation. The initBaseData method is an abstract method or a specific implementation method defined in the Activity base class, and is used to initialize some global or shared data when the Activity is created.
[0053] This Android cold start optimization method combines thread pool asynchronous loading, giving priority to using caches for the home page display, delaying the creation of non-home pages, delaying the loading of non-core SDKs, and the method of setting the loading priority order, achieving "instant start" for cold starts. It has cold-optimized the time from start to the home page from 4 seconds to 0.5 seconds, greatly improving the user experience.
[0054] The circuits, electronic components, and modules involved are all prior arts and can be fully implemented by those skilled in the art without further elaboration. The content protected by this application does not involve improvements to software and methods either.
[0055] The present invention is not limited to the above embodiments. No matter what changes are made in its shape or structure, they all fall within the protection scope of the present invention. The protection scope of the present invention is defined by the appended claims. Those skilled in the art can make various changes or modifications to these embodiments without departing from the principles and essence of the present invention, and these changes and modifications all fall within the protection scope of the present invention.
Claims
1. An Android cold start optimization method, characterized in that: The Android cold start optimization method comprises the following steps: S1. All business logic codes of the Application class are split and optimized, and necessary initialization is retained, and unnecessary codes are removed; S2. All logic of the first Activity page is deleted, only the basic jump function is retained, and the background is set to transparent; S3. Home page Activity optimization.
2. The Android cold start optimization method as claimed in claim 1, characterized in that: The Application process logic in the step (S1) is in the AttachBaseContext method, which initializes the necessary content: mmkv storage initialization, and App's SharedPreferences class initialization.
3. The Android cold start optimization method as claimed in claim 1, characterized in that: The Application process logic in the step (S1) is in the onCreate method, where the Ali routing Arouter is initialized, the business base class and the tool class are initialized, and then the splash screen class LogoSplashActivity is started.
4. The Android cold start optimization method as claimed in claim 1, characterized in that: The home page Activity optimization method in step (S3) specifically includes the following steps: a. The advertisement splash screen content is displayed first, and under the advertisement page, the initialization creation operation of the current page of the main Activity is performed, including loading the cache data to display the UI page; b. After the current page of the main Activity is created, remove the ad splash screen page first, and then initialize the creation of non-current pages. Then, according to the code priority, initialize each SDK and obtain data operations.
5. The Android cold start optimization method as claimed in claim 1, characterized in that: Before the original function of the LogoSplashActivity process logic in the step (S2) is modified, the advertisement display and jump processing functions are executed here. Since the XML parsing of advertisement layout is time-consuming, all advertisement logics of the splash screen page are removed here, and the page is set to transparent. In this way, the time consumption in the splash screen page is reduced from the original statistical 1000ms+ to about 100ms.
6. The Android cold start optimization method as claimed in claim 1, characterized in that: The MainActivity process logic in step (S2) includes: (1) In setContentView, display the ad splash screen first, and then in initBaseData, start processing the logic of the home page; (2) When you install the App for the first time, an authorization pop-up window will be displayed. After the authorization is granted, the InitAppUtils.initWithAgree method will be executed. The method contains the initDataWithAgree method and the initSDKWithAgree method. As the names indicate, the initDataWithAgree method is used to obtain business data and cache data, and the initSDKWithAgree method is used to initialize the SDK. The thread pool logic is added to the method, and asynchronous methods are used to solve the time-consuming problem. (3) The cold start of the secondary+ does not have an authorization pop-up window or an advertisement. It will be executed in sequence according to the InitAppUtils.initWithAgree method in (2). After continuing the InitAppUtils.initWithAgree method in (2), the initMain method will be executed. This method is used to create visible home page content (after executing initMain, the hideAndLateInit method will be executed to display the home page content; (4) When there are advertisements in the cold start of the secondary+, the showAd method will be executed at the same time as the initMain method is executed to display the advertisements. After the advertisements are executed, the hideAndLateInit method will be executed to remove the advertisements and perform subsequent initialization work, see the initByLowProperty method; the initByLowProperty method integrates the thread pool and loads the priority sequence, so as to achieve the "second start" function without card congestion.
7. The Android cold start optimization method as claimed in claim 1, characterized in that: In the step (S1), Application is the base class of Android applications, which provides application lifecycle management and an overall application context environment. Application is an abstract class, and it is usually necessary to create a custom application class by inheriting and implementing its abstract methods.
8. The Android cold start optimization method as claimed in claim 1, characterized in that: In the step (S3), the Activity is a user interface, which displays various UI elements by loading a specified layout file and processes the interactive events of these UI elements, such as clicks and text input. Different Activities can jump to each other, connecting different pages in series to complete a specific operation process.
9. The Android cold start optimization method as claimed in claim 1, characterized in that: The setContentView method is a very important method in Android development. It is used to set the layout for the current Activity. The setContentView method is usually called in the onCreate method of the Activity to specify the layout to be displayed by the Activity.
10. The Android cold start optimization method according to claim 1, characterized in that: The initBaseData method is usually a custom method used to initialize base class data in Android application development, especially when using Activity base class encapsulation. The initBaseData method is an abstract method or specific implementation method defined in the Activity base class, which is used to initialize some global or shared data when the Activity is created.