Activity starting method and device, storage medium and processor
By loading View resources in the Activity in stages, optimizing the View hierarchy and lazy loading, the problem of slow interface startup was solved, and a fast startup user experience was achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHONGQING CHANGAN TECH CO LTD
- Filing Date
- 2023-03-27
- Publication Date
- 2026-07-31
AI Technical Summary
The existing Activity launch method takes a long time to load View resources, resulting in slow interface startup and affecting user experience.
By loading View resources in stages, first loading the primary View resource, and then loading the secondary View resource after the primary View resource is loaded, and dynamically adding them using the onFirstDrawFinish and addView functions, the View hierarchy is optimized and lazy loading is optimized.
It improves the interface startup speed, giving users a fast startup experience both visually and perceptually, and avoids loading a large number of time-consuming View resources at startup.
Smart Images

Figure CN116521256B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and more specifically to an Activity launch method, an Activity launch device, a machine-readable storage medium, and a processor. Background Technology
[0002] Activity is one of the four most basic and common components in the Android system. An Activity provides a screen that offers users an interactive interface.
[0003] When a user launches an app, the program correspondingly starts launching Activities. When a user opens an app, especially for the first time after booting up, since the app has never been launched before, the process will load many time-consuming resources, especially View resources. When our View hierarchy is complex, Android will take a long time to draw the View. Users may feel that the interface is too slow to display, or even experience a white screen, which seriously affects the user experience.
[0004] Therefore, the existing Activity launch method suffers from slow interface startup. Summary of the Invention
[0005] The purpose of this invention is to provide an Activity launch method, an Activity launch device, a machine-readable storage medium, and a processor. This Activity launch method avoids loading many time-consuming View resources during startup, improves loading speed, and makes the interface launch faster, thereby giving users a fast startup experience in terms of perception and vision.
[0006] To achieve the above objectives, embodiments of the present invention provide an Activity launch method, including:
[0007] In response to an Activity launch request, load the first View resource in the Activity;
[0008] After the first View resource is loaded, the second View resource in the Activity is loaded to complete the Activity startup.
[0009] In this embodiment of the application, loading the second View resource in the Activity includes:
[0010] Start loading the second View resource in the Activity;
[0011] Once the second View resource has finished loading, add the second View resource to the ContentView.
[0012] In this embodiment of the application, the step of initiating the loading of the second View resource in the Activity includes:
[0013] The onFirstDrawFinish function is called, and within the onFirstDrawFinish function, the onDrawSecondView function is called to begin loading the second View resource in the Activity.
[0014] In this embodiment of the application, adding the second View resource to the ContentView includes:
[0015] Add the loaded second View resource to the ContentView using addView.
[0016] In this embodiment of the application, loading the first View resource in the Activity includes:
[0017] The first View resource in the Activity is loaded using the setContentView function.
[0018] In this embodiment of the application, it also includes:
[0019] Divide the Views in the Activity into primary load Views and secondary load Views;
[0020] The primary loaded View is used as the first View resource;
[0021] The secondary loaded View is used as the second View resource.
[0022] In this embodiment of the application, loading the second View resource in the Activity after the first View resource has been loaded includes:
[0023] By listening to the drawing event of the first View resource, the second View resource in the Activity is loaded after the first View resource is drawn.
[0024] A second aspect of this application provides an Activity launching device, comprising:
[0025] The first loading module is used to load the first View resource in the Activity in response to the Activity startup request;
[0026] The second loading module is used to load the second View resource in the Activity after the first View resource has been loaded, so as to complete the Activity startup.
[0027] A third aspect of this application provides a processor configured to execute the Activity launch method described above.
[0028] A fourth aspect of this application provides a machine-readable storage medium storing instructions that, when executed by a processor, configure the processor to perform the Activity launch method described above.
[0029] The beneficial effects of this invention are:
[0030] In response to an Activity launch request, the first View resource in the Activity is loaded, followed by the second View resource to complete the Activity launch. This ensures that View resources are loaded in stages while maintaining absolute optimization of the View hierarchy, achieving distributed View loading. During the loading process, because the first View resource is loaded first, loading many time-consuming View resources at launch is avoided, improving loading speed and making the interface launch faster. This provides users with a faster launch experience both perceptually and visually.
[0031] Other features and advantages of the embodiments of the present invention will be described in detail in the following detailed description section. Attached Figure Description
[0032] The accompanying drawings are provided to further illustrate embodiments of the present invention and form part of the specification. They are used together with the following detailed description to explain the embodiments of the present invention, but do not constitute a limitation thereof. In the drawings:
[0033] Figure 1 The illustration shows a flowchart of an Activity launch method according to an embodiment of this application;
[0034] Figure 2 This illustration schematically shows a flowchart of the Activity launch function call according to an embodiment of the present application;
[0035] Figure 3 This schematic diagram illustrates a structural block diagram of an Activity launching device according to an embodiment of the present application;
[0036] Figure 4 The diagram illustrates the internal structure of a computer device according to an embodiment of this application.
[0037] Among them, 410-first loading module; 420-second loading module; A01-processor; A02-network interface; A03-internal memory; A04-display screen; A05-input device; A06-non-volatile storage medium; B01-operating system; B02-computer program. Detailed Implementation
[0038] The embodiments of the present invention will be described below with reference to the accompanying drawings and preferred embodiments. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be understood that the preferred embodiments are only for illustrating the present invention and not for limiting the scope of protection of the present invention.
[0039] The specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are for illustration and explanation only and are not intended to limit the scope of the present invention.
[0040] It should be noted that if the embodiments of this application involve descriptions such as "first" or "second," these descriptions are for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, features defined with "first" or "second" may explicitly or implicitly include at least one of those features. Furthermore, the technical solutions of the various embodiments can be combined with each other, but this must be based on the ability of those skilled in the art to implement them. When the combination of technical solutions is contradictory or impossible to implement, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed in this application.
[0041] Please refer to Figures 1-2 , Figure 1 This illustration schematically shows a flowchart of an Activity launch method according to an embodiment of this application. Figure 2 The flowchart illustrating the Activity launch function call according to an embodiment of this application is shown.
[0042] The Activity launch method includes the following steps:
[0043] Step 210: In response to the Activity launch request, load the first View resource in the Activity; in this embodiment, when the user launches the APP and starts the main interface, the Activity launch request is obtained. The first View resource may include one or more Views, which may be pre-planned Views intended to be displayed to the user first.
[0044] In some embodiments, loading the first View resource can be done using the existing Activity loading mechanism, specifically by loading the first View resource in the Activity using the `setContentView` function. The purpose of `setContentView` is to place the layout file in the Activity for display. It loads the View above the root view, so when displaying views, the root view is displayed first, followed by child views, and so on, until all views are displayed. Using `setContentView` to load the first View resource helps ensure that the views within that first View resource are displayed correctly.
[0045] Step 220: After the first View resource is loaded, the second View resource in the Activity is loaded to complete the Activity launch. In this embodiment, the second View resource can be any View other than the View in the first View resource. It should be noted that the first View resource and the second View resource can be planned according to actual needs.
[0046] In some embodiments, when the View hierarchy is complex, the Views can be prioritized to obtain first View resources and second View resources. Specifically, this includes the following steps:
[0047] First, divide the Views in the Activity into primary loading Views and secondary loading Views;
[0048] Then, the primary loaded View is used as the first View resource; the secondary loaded View is used as the second View resource.
[0049] In this embodiment, the division of Views in the Activity can be based on hierarchy. For example, the highest-level View can be loaded first, and other Views can be loaded second. By dividing the Views, the loading of Views can be distributed, avoiding the problem of long loading times when loading all Views at once.
[0050] In some embodiments, the loading of the second View resource can be accomplished using a delayed loading scheme, specifically, the second View resource is loaded after the first View resource has been loaded. The determination of whether the loading of the first View resource is complete can be made using event listening. That is, loading the second View resource in the Activity after the first View resource has been loaded includes: listening to the drawing event of the first View resource, and loading the second View resource in the Activity after the first View resource has been drawn. The delay ensures that loading begins only after the first View resource has completed its layout. Using event listening ensures that loading of the second View resource begins only after the first View resource has been loaded, thus guaranteeing a delayed loading of the second View resource.
[0051] In some embodiments, the loading of the second View resource can be achieved using a dynamic loading scheme. The steps for loading the second View resource in the Activity are as follows:
[0052] First, the loading of the second View resource in the Activity is initiated. Specifically, during the loading process, the `onFirstDrawFinish` function can be called, and within `onFirstDrawFinish`, the `onDrawSecondView` function is called to begin loading the second View resource in the Activity. After the first View resource is loaded, a callback to the `onFirstDrawFinish` function is invoked, where the `onDrawSecondView` function is called. In this embodiment, the `onFirstDrawFinish` function is used to confirm the completion of loading the first View resource, and the `onDrawSecondView` function is used to load the second View resource.
[0053] Then, once the second View resource has finished loading, it is added to the ContentView. This can be done by adding the loaded second View resource to the ContentView using the `addView` function. `addView` allows for dynamic loading of Views.
[0054] In some embodiments, the loading of the second View resource can also be achieved using a delayed + dynamic loading scheme. Specifically, it can be achieved by listening to the drawing event of the first View resource, loading the second View resource after the first View resource has been drawn, and finally loading the second View resource into the ContentView using the addView method. This achieves a delayed + dynamic loading scheme, which allows the Activity to prioritize the display of the first View resource, giving users a fast startup experience in terms of perception and visuals.
[0055] For example, such as Figure 2 As shown, after the user launches the APP, the main interface starts. First, the first View resource is loaded, namely S1 in the figure. After the first View resource is completed, the onFirstDrawFinish function is called. In this function, the onDrawSecondView function is called to start loading the second View resource. Finally, the loaded View is added to the ContentView through addView and presented to the user.
[0056] In the above implementation, by responding to the Activity launch request, the first View resource in the Activity is loaded, followed by the second View resource, to complete the Activity launch. This ensures that View resources are loaded step-by-step with absolute optimization of the View hierarchy, achieving distributed View loading. During the loading process, since the first View resource is loaded first, loading many time-consuming View resources at launch is avoided, improving loading speed and making the interface launch faster, thus providing users with a fast-starting experience both perceptually and visually. By hierarchically dividing the Views into primary and secondary loadable Views, the Activity can prioritize displaying necessary Views, facilitating flexible control over the display order of Views for application in various scenarios.
[0057] Figure 1 This is a flowchart illustrating the Activity launch method in this embodiment. It should be understood that, although... Figure 1 The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order in which these steps are executed, and they can be performed in other orders. Figure 1At least some of the steps in the process may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.
[0058] In one embodiment, such as Figure 3 As shown, Figure 3 This schematically illustrates a structural block diagram of an Activity launching device according to an embodiment of the present application. An Activity launching device is provided, including a first loading module 410 and a second loading module 420:
[0059] The first loading module 410 is used to load the first View resource in the Activity in response to the Activity startup request;
[0060] The second loading module 420 is used to load the second View resource in the Activity to complete the Activity startup.
[0061] In the above implementation process, the first loading module 410 responds to the Activity launch request by loading the first View resource in the Activity, and the second loading module 420 loads the second View resource in the Activity to complete the Activity launch. This ensures that View resources are loaded step by step while maintaining absolute optimization of the View hierarchy, achieving distributed View loading. During the loading process, since the first View resource is loaded first, loading many time-consuming View resources at startup is avoided, improving loading speed and making the interface launch faster, thus providing users with a fast-starting experience both perceptually and visually. By dividing the View hierarchy into primary and secondary loaded Views, the Activity can prioritize displaying necessary Views, facilitating flexible control over the display order of Views for application in various scenarios.
[0062] The Activity launch device includes a processor and a memory. The first loading module 410 and the second loading module 420 are stored in the memory as program units, and the processor executes the program modules stored in the memory to implement the corresponding functions.
[0063] The processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and adjusting kernel parameters can speed up the interface startup process.
[0064] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0065] This invention provides a machine-readable storage medium storing a program that, when executed by a processor, implements the Activity launch method.
[0066] This invention provides a processor for running a program, wherein the program executes the Activity launch method during runtime.
[0067] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 4 As shown, the computer device includes a processor A01, a network interface A02, a display screen A04, an input device A05, and a memory (not shown) connected via a system bus. The processor A01 provides computing and control capabilities. The memory includes internal memory A03 and a non-volatile storage medium A06. The non-volatile storage medium A06 stores an operating system B01 and a computer program B02. The internal memory A03 provides an environment for the operation of the operating system B01 and the computer program B02 stored in the non-volatile storage medium A06. The network interface A02 is used for communication with external terminals via a network connection. When the computer program is executed by the processor A01, it implements an Activity launch method. The display screen A04 can be a liquid crystal display (LCD) or an e-ink display. The input device A05 can be a touch layer covering the display screen, buttons, a trackball, or a touchpad mounted on the computer device casing, or an external keyboard, touchpad, or mouse.
[0068] Those skilled in the art will understand that Figure 4 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0069] In one embodiment, the Activity launching device provided in this application can be implemented as a computer program, and the computer program can be implemented as follows: Figure 4 It runs on the computer device shown. The computer device's memory can store the various program modules that make up the Activity launch device, for example, Figure 3The first loading module 410 and the second loading module 420 are shown. The computer program, composed of the various program modules, causes the processor to execute the steps in the Activity launch methods of the various embodiments of this application described in this specification.
[0070] Figure 4 The computer equipment shown can be used as follows Figure 3 The first loading module 410 in the Activity launching device shown executes step 210. The computer device can execute step 220 through the second loading module 420.
[0071] This application provides a device, which includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs the following steps:
[0072] In response to an Activity launch request, load the first View resource in the Activity;
[0073] After the first View resource is loaded, the second View resource in the Activity is loaded to complete the Activity startup.
[0074] In one embodiment, loading the second View resource in the Activity includes:
[0075] Start loading the second View resource in the Activity;
[0076] Once the second View resource has finished loading, add the second View resource to the ContentView.
[0077] In one embodiment, the initiation of loading the second View resource in the Activity includes:
[0078] The onFirstDrawFinish function is called, and within the onFirstDrawFinish function, the onDrawSecondView function is called to begin loading the second View resource in the Activity.
[0079] In one embodiment, adding the second View resource to the ContentView includes:
[0080] Add the loaded second View resource to the ContentView using addView.
[0081] In one embodiment, loading the first View resource in the Activity includes:
[0082] The first View resource in the Activity is loaded using the setContentView function.
[0083] In one embodiment, it also includes:
[0084] Divide the Views in the Activity into primary load Views and secondary load Views;
[0085] The primary loaded View is used as the first View resource;
[0086] The secondary loaded View is used as the second View resource.
[0087] In one embodiment, loading the second View resource in the Activity after the first View resource has been loaded includes:
[0088] By listening to the drawing event of the first View resource, the second View resource in the Activity is loaded after the first View resource is drawn.
[0089] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0090] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0091] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0092] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0093] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0094] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0095] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0096] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0097] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
[0098] The above embodiments are merely preferred embodiments provided to fully illustrate the present invention, and the scope of protection of the present invention is not limited thereto. Equivalent substitutions or modifications made by those skilled in the art based on the present invention are all within the scope of protection of the present invention.
Claims
1. An Activity starting method, characterized by, include: The Views in the Activity are divided into a primary loading View and a secondary loading View. The primary loading View is used as the first View resource, and the secondary loading View is used as the second View resource. In response to an Activity launch request, load the first View resource in the Activity; After the first View resource is loaded, the second View resource in the Activity is loaded to complete the Activity startup; The loading of the second View resource in the Activity includes: Start loading the second View resource in the Activity; Once the second View resource has finished loading, add the second View resource to the ContentView; The step of adding the second View resource to the ContentView includes: The loaded second View resource is added to ContentView using addView to achieve dynamic View loading; Wherein, loading the second View resource in the Activity after the first View resource has been loaded includes: By listening to the drawing event of the first View resource, the second View resource in the Activity is loaded after the first View resource is drawn.
2. The Activity launch method according to claim 1, characterized in that, The process of initiating and loading the second View resource in the Activity includes: The onFirstDrawFinish function is called, and within the onFirstDrawFinish function, the onDrawSecondView function is called to begin loading the second View resource in the Activity.
3. The Activity launch method according to claim 1, characterized in that, Loading the first View resource in the Activity includes: The first View resource in the Activity is loaded using the setContentView function.
4. An Activity launching device, characterized in that, include: The first loading module is used to divide the Views in the Activity into a primary loading View and a secondary loading View, using the primary loading View as the first View resource and the secondary loading View as the second View resource; in response to the Activity startup request, it loads the first View resource in the Activity. The second loading module is used to load the second View resource in the Activity after the first View resource has been loaded, so as to complete the Activity startup; wherein, loading the second View resource in the Activity includes: starting the loading of the second View resource in the Activity; and adding the second View resource to the ContentView after the second View resource has been loaded; wherein, adding the second View resource to the ContentView includes: adding the loaded second View resource to the ContentView using addView to achieve dynamic loading of the View; wherein, loading the second View resource in the Activity after the first View resource has been loaded includes: listening to the drawing event of the first View resource, and loading the second View resource in the Activity after the first View resource has been drawn.
5. A processor, characterized in that, It is configured to perform the Activity launch method as described in any one of claims 1 to 3.
6. A machine-readable storage medium storing instructions thereon, characterized in that, When executed by a processor, this instruction causes the processor to be configured to perform the Activity launch method as described in any one of claims 1 to 3.