Interface loading method and device and electronic equipment

By determining the business type in Android applications, using different interface loading methods, using preset buffer pools and child thread callback mechanisms, the interface lag caused by UI operations is solved, and smooth interface loading is achieved.

CN120353524APending Publication Date: 2025-07-22NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202510185953.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-19
Publication Date
2025-07-22

AI Technical Summary

Technical Problem

In Android applications, UI operations perform time-consuming operations on the main thread, causing the interface to stutter, affecting the user experience.

Method used

By determining the business type of the target Android application, different interface loading methods are adopted: when the first business type is used, the main thread obtains the interface object from the preset buffer pool; when the second business type is used, the child thread completes the interface object creation and updates to the main thread through a callback.

Benefits of technology

It reduces interface lag, avoids the main thread being blocked, ensures the smoothness of Android applications, and adapts to different business scenario needs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120353524A_ABST
    Figure CN120353524A_ABST
Patent Text Reader

Abstract

The invention provides an interface loading method and apparatus, and an electronic device. The method comprises the steps of determining a target service type corresponding to a current interface loading scene of a target Android application; if the target service type is a first service type, the main thread obtains an interface object from a preset buffer pool, generates an interface element based on the interface object, and displays the interface element on a target Android application interface; the preset buffer pool is used for storing a plurality of interface objects pre-created by the sub-thread; and if the target service type is a second service type, returning to the main thread in a callback updating mode after the sub-thread completes the creation of the interface object, so that the main thread generates an interface element based on the interface object and updates the interface element to an interface corresponding to the target Android application. In the mode, different interface asynchronous loading modes are used for different service types, and when the interface is loaded, after the interface object is asynchronously loaded in the sub-thread, the interface is switched back to the main thread to execute the updating operation of the interface element, so that the interface jamming phenomenon is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the technical field of interface design, and more particularly to an interface loading method, apparatus, and electronic device. Background Art

[0002] UI operations in Android applications must be executed on the main thread (also known as the UI thread). If time-consuming operations are performed on the main thread, such as loading a large amount of data or complex layouts, it will cause the interface to freeze and affect the user experience. During the development of Android applications, the creation and update operations of the UI are defaultly executed on the main thread. Therefore, during the loading process of some complex or business-heavy pages, it is easy to cause freezing problems. Summary of the Invention

[0003] The present disclosure provides an interface loading method, apparatus, and electronic device to avoid interface loading freezes and adopt different interface loading methods according to different business scenario requirements, so as to better adapt to different business scenario requirements.

[0004] In a first aspect, the present disclosure provides an interface loading method, which is applied to an electronic device installed with a target Android application. The method includes: determining a target business type corresponding to the current interface loading scenario of the target Android application; where the target business type is a first business type or a second business type; the first business type and the second business type perform interface element loading through different loading methods; when the target business type is the first business type, controlling the main thread to obtain an interface object from a preset buffer pool, and generating interface elements based on the interface object to be displayed on the interface corresponding to the target Android application; where the preset buffer pool is used to store multiple interface objects pre-created by a child thread; when the target business type is the second business type, after the child thread completes the creation of the interface object, returning to the main thread through a callback update method, so that the main thread generates interface elements based on the interface object and updates the interface elements to the interface corresponding to the target Android application.

[0005] Second aspect, the present disclosure provides an interface loading device, which is applied to an electronic device with a target Android application installed therein. The device includes: a service type determination module, configured to determine a target service type corresponding to the current interface loading scenario of the target Android application; wherein the target service type is a first service type or a second service type; the first service type and the second service type perform interface element loading through different loading methods; a first interface loading module, configured to, when the target service type is the first service type, control the main thread to obtain an interface object from a preset buffer pool, and generate interface elements based on the interface object to be displayed on the interface corresponding to the target Android application; wherein the preset buffer pool is used to store multiple interface objects pre-created by a child thread; a second interface loading module, configured to, when the target service type is the second service type, return to the main thread in a callback update manner after the child thread completes the creation of the interface object, so that the main thread generates interface elements based on the interface object and updates the interface elements to the interface corresponding to the target Android application.

[0006] Third aspect, the present disclosure provides an electronic device, which includes a processor and a memory. The memory stores machine-executable instructions that can be executed by the processor, and the processor executes the machine-executable instructions to implement the above interface loading method.

[0007] Fourth aspect, the present disclosure provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions cause the processor to implement the above interface loading method.

[0008] The embodiments of the present disclosure bring the following beneficial effects:

[0009] An interface loading method, device, and electronic device provided by the present disclosure first determine a target service type corresponding to the current interface loading scenario of a target Android application; wherein, the target service type is a first service type or a second service type; the first service type and the second service type load interface elements through different loading methods; when the target service type is the first service type, control the main thread to obtain an interface object from a preset buffer pool, and generate interface elements based on the interface object and display them on the interface corresponding to the target Android application; wherein, the preset buffer pool is used to store multiple interface objects pre-created by a child thread; when the target service type is the second service type, after the child thread completes the creation of the interface object, return to the main thread through a callback update method, so that the main thread generates interface elements based on the interface object, and updates the interface elements to the interface corresponding to the target Android application. In this method, when loading the interface, after asynchronously loading the interface object in the child thread, switch back to the main thread to perform the update operation of the interface elements, thereby reducing the interface lag phenomenon, avoiding blocking of the main thread, and ensuring the fluency of the Android application; at the same time, this method uses different interface asynchronous loading methods for different service types, so as to better adapt to the requirements of different service scenarios.

[0010] Other features and advantages of the present disclosure will be described in the following specification, or some features and advantages can be inferred from the specification or determined without doubt, or can be known by implementing the above technologies of the present disclosure.

[0011] To make the above objects, features, and advantages of the present disclosure more obvious and understandable, the following specifically enumerates preferred embodiments and, in conjunction with the accompanying drawings, makes a detailed description as follows. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] In order to more clearly illustrate the specific embodiments of the present disclosure or the technical solutions in the prior art, the following will briefly introduce the drawings required for use in the description of the specific embodiments or the prior art. Obviously, the following drawings are some embodiments of the present disclosure. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0013] Figure 1 It is a flowchart of an interface loading method provided by an embodiment of the present disclosure;

[0014] Figure 2 It is a schematic diagram of a loading method for the first service type provided by an embodiment of the present disclosure;

[0015] Figure 3 It is a schematic diagram of a loading method for the second service type provided by an embodiment of the present disclosure;

[0016] Figure 4Execution logic diagram of the Fragment lifecycle provided by the embodiments of the present disclosure;

[0017] Figure 5 Schematic diagram of another loading method for the second service type provided by the embodiments of the present disclosure;

[0018] Figure 6 Schematic diagram of the structure of an interface loading device provided by the embodiments of the present disclosure;

[0019] Figure 7 Schematic diagram of the structure of an electronic device provided by the embodiments of the present disclosure. Detailed implementation manners

[0020] To make the objectives, technical solutions and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present disclosure. Obviously, the described embodiments are some, but not all, of the embodiments of the present disclosure. Components of the embodiments of the present disclosure generally described and illustrated in the figures herein may be arranged and designed in a variety of different configurations.

[0021] Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the present disclosure claimed, but merely represents selected embodiments of the present disclosure. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present disclosure without creative efforts shall fall within the protection scope of the present disclosure.

[0022] To avoid the problem of interface lag caused by the fact that the creation and update operations of Android applications on the UI are defaultly executed in the main thread. In the related art, some optimization solutions related to Views are provided: reducing the View layout hierarchy, using the merge tag; avoiding over-drawing problems; avoiding performing a large number of time-consuming operations in the onDraw method of the View; using ViewStub to achieve lazy loading. However, the optimization effects of the optimization solutions provided in the related art are limited, and solutions such as lazy loading will also block the main thread, only changing the lag from before entering the interface to after entering the interface.

[0023] Based on the above problems, the embodiments of the present disclosure provide an interface loading method, device and electronic device, and this technology can be applied to the loading scenarios of any interface in Android applications.

[0024] To facilitate the understanding of the present disclosure, first understand an interface loading method in the present disclosure. This method is applied to an electronic device installed with a target Android application. As Figure 1 shown, the method includes the following specific steps:

[0025] Step S102: Determine the target business type corresponding to the current interface loading scenario of the target Android application; wherein, the target business type is the first business type or the second business type; the first business type and the second business type load interface elements through different loading methods.

[0026] The above-mentioned target Android application can be any application program using the Android system. The target business type corresponding to the current interface loading scenario of the target Android application can be any one of multiple preset business types. The multiple preset business types at least include the first business type and the second business type. Different business types use different loading methods to load interface elements, thereby avoiding interface lag.

[0027] In specific implementation, the specific types corresponding to the above-mentioned first business type and second business type can be determined according to R & D requirements. For example, the first business type can be a scenario that requires creating the same interface object multiple times, and the second business type can be a scenario that only creates the interface object once, etc.

[0028] Step S104: When the target business type is the first business type, control the main thread to obtain the interface object from the preset buffer pool, and generate interface elements based on the interface object and display them on the interface corresponding to the target Android application; wherein, the preset buffer pool is used to store multiple interface objects pre-created by the sub-thread.

[0029] In specific implementation, for the first business type, it is necessary to maintain a preset buffer pool with a settable capacity. After starting the preset buffer pool, it will continuously create interface objects in the sub-thread and put them into the preset buffer pool. When the main thread constructs the interface, it synchronously obtains the corresponding interface object from the buffer pool, thereby effectively reducing the situation of main thread blockage.

[0030] It should be noted that the above-mentioned main thread is the thread created by the operating system when the application program starts, and is responsible for executing all UI (UI is the user interface) updates, user interactions, and life cycle management tasks of the application program. In an Android application, the main thread is single-threaded, and all UI operations and event handling are executed on the same thread. Although Android applications restrict that UI operations must be executed on the main thread, there is no restriction on the thread for UI creation (equivalent to interface object creation). Therefore, after asynchronously loading the UI in the sub-thread, it can be switched back to the main thread to execute the UI update operation. The above-mentioned sub-thread is created by the main thread and is used to execute time-consuming operations, but the sub-thread cannot directly update UI components.

[0031] Step S106, when the target service type is the second service type, after the creation of the interface object is completed in the child thread, return to the main thread through the callback update method, so that the main thread generates interface elements based on the interface object and updates the interface elements to the interface corresponding to the target Android application.

[0032] In specific implementation, for the second service type, by virtue of the characteristics of Kotlin coroutines and the Android interface life cycle, the logic of loading UI objects (equivalent to the above-mentioned interface objects) in the child thread and updating the UI in the main thread is realized, thus effectively reducing the situation of main thread blockage.

[0033] In an optional embodiment, when the target service type is the second service type, the main thread creates a LayoutInflater through an externally passed UiContext, thus avoiding the problem of not supporting LayoutInflater.Factory or not supporting LayoutInflater.Factory2.

[0034] In the above interface loading method, after asynchronously loading the interface object in the child thread when loading the interface, switch back to the main thread to perform the update operation of the interface elements, thereby reducing the interface lag phenomenon, avoiding the blockage of the main thread, and ensuring the fluency of the Android application; at the same time, this method uses different interface asynchronous loading methods for different service types, so as to better meet the requirements of different service scenarios.

[0035] The following optional embodiment is used to describe the interface loading method corresponding to the first service type.

[0036] The process of creating and initializing an interface object (also called a View) is time-consuming, including operations such as parsing the layout file, measuring, laying out, and drawing. Creating the required View instances in advance in the child thread and storing them in memory can effectively reduce the lag when the interface is displayed and the blockage of the UI thread, adopting an optimization scheme of trading space for time.

[0037] Specifically, the multiple interface objects stored in the above-mentioned preset buffer pool are created in the following way: automatically create interface objects through the child thread and cache the created interface objects into the preset buffer pool; when the number of object instances of the interface objects stored in the preset buffer pool reaches the preset number threshold, control the child thread to stop creating interface objects until the number of object instances of the interface objects stored in the preset buffer pool is less than the preset number threshold. This preset number threshold can be determined according to R & D requirements.

[0038] In specific implementation, the present disclosure provides a management entry for a preset buffer pool. A user can start or close the preloading manager at an appropriate time. Here, the preloading manager is the aforementioned sub-thread. After the sub-thread is started, it will automatically cache the interface objects. When the interface objects in the preset buffer pool are taken out, the sub-thread will continue to create new interface objects and put them into the preset buffer pool.

[0039] The present disclosure provides a thread-safe shared cache pool (equivalent to the aforementioned preset buffer pool) for caching the created interface objects. When the capacity of the preset cache pool reaches the upper limit, the sub-thread will be blocked, that is, the sub-thread will stop creating interface objects, thereby avoiding resource waste; if the capacity of the preset cache pool does not reach the upper limit, the interface objects will be instantiated in the sub-thread and added to the preset cache pool until the capacity of the preset cache pool reaches the upper limit. Here, the preset buffer pool reaching the upper limit means that the number of interface objects stored in the preset buffer pool reaches a preset number threshold.

[0040] Based on the above description, the specific process of the aforementioned control main thread obtaining an interface object from the preset buffer pool and generating interface elements based on the interface object for display on the interface corresponding to the target Android application may include: when the main thread needs an interface object, determining whether there is an available interface object in the preset buffer pool; if there is, controlling the main thread to obtain the interface object from the preset buffer pool and generating interface elements based on the interface object for display on the interface corresponding to the target Android application.

[0041] In specific implementation, the main thread will synchronously obtain available preloaded interface objects from the preset buffer pool when constructing the interface. However, when the main thread quickly takes out interface objects from the preset buffer pool, if the creation speed of the interface objects by the sub-thread cannot keep up with the taking-out speed, it is possible that there are no available interface objects in the preset buffer pool. At this time, the following interface object method needs to be executed: if there are no available interface objects in the preset buffer pool, controlling the main thread to create interface objects and generating interface elements based on the interface objects for display on the interface corresponding to the target Android application.

[0042] Specifically, if there are no available interface objects in the preset buffer pool, the present disclosure provides a degradation solution, that is, it will continue to create the required interface objects in the main thread to ensure the normal operation of the program.

[0043] As Figure 2 shown is a schematic diagram of a loading method for a first service type provided by an embodiment of the present disclosure. Figure 2The Producer in it runs on a child thread, responsible for parsing XML files, preloading the required View objects (equivalent to the above-mentioned interface objects), and writing them into a preset cache pool; the Consumer runs on the UI thread (equivalent to the above-mentioned main thread), and attempts to retrieve View objects from the preset cache pool when a View object is needed; the Shared Buffer is a thread-safe shared memory (equivalent to the above-mentioned preset buffer pool) for storing preloaded View objects.

[0044] This method is based on a typical producer-consumer model to implement a multi-threaded task queue system, where the producer thread (equivalent to the above-mentioned child thread) continuously generates tasks and puts them into the queue (equivalent to the above-mentioned preset buffer pool), and the consumer thread (equivalent to the above-mentioned main thread) retrieves tasks from the queue and processes them. This method can effectively improve the concurrency performance and resource utilization rate of the system.

[0045] The following alternative embodiments are used to describe the interface loading method corresponding to the second service type.

[0046] When an Android application needs to load the UI, the work of creating the UI is migrated to an IO thread (equivalent to a child thread) for execution, and then switched back to the main thread to update the view after the UI is created.

[0047] The present disclosure provides two access schemes for asynchronous loading.

[0048] The first one is the scheme of controlling the Fragment life cycle: applicable to scenarios where Fragments are used as page carriers.

[0049] Specifically, after the creation of the interface object is completed in the child thread, it returns to the main thread through the callback update method, so that the main thread generates interface elements based on the interface object and updates the interface elements to the interface corresponding to the target Android application. The specific process may include: restricting the maximum life cycle of the Fragment component used to create the interface object and interface elements in the main thread to the onCreate stage to prevent the Fragment component from executing the life cycle after the onCreate stage before the interface object is created; after the creation of the interface object is completed in the child thread, the interface object is passed into the main thread through the callback update method, so that the main thread generates interface elements based on the interface object through the Fragment component and updates the interface elements to the interface corresponding to the target Android application.

[0050] In specific implementation, the Fragment component plays an important role in Android applications and can help developers build flexible, modular, and highly adaptable user interfaces. As the lifecycle manager of the UI, the Fragment component completes operations such as UI creation, update, and user interaction in the main thread. However, in this disclosure, the maximum lifecycle of the Fragment is restricted to the onCreate stage, preventing the Fragment's lifecycle from proceeding further. A child thread is then started to load the UI object, and the restriction is lifted after the UI object is loaded to allow the Fragment lifecycle to continue. This approach ensures that the UI to be created can be initialized in a child thread, avoiding blocking the main thread. At the same time, it ensures that the main thread can safely operate on the UI, preventing UI operations from being performed before the UI is initialized.

[0051] As Figure 3 FIG. is a schematic diagram of a loading method for a second service type provided by an embodiment of this disclosure. In Android development, the Fragment is a commonly used component that allows for the creation of modular UI components within an Activity. The Fragment has its own independent lifecycle, which is closely related to the lifecycle of the Activity (onCreated, onCreateView... onStop, onDestroyView, onDestroy...). These methods provide a structured way to manage the creation of the Fragment, the creation of the view, user interaction, and the destruction process. Lifecycle is a tool provided by the official to manage the lifecycles of Android application components (such as Activity, Fragment, Service, etc.), defining unified events (Event) and states (State) to manage the lifecycles of different application components. Figure 3 shows the Lifecycle state (State) corresponding to each lifecycle method of the Fragment.

[0052] By restricting the maximum lifecycle of the Fragment, this approach avoids executing the lifecycle after onCreate before the View (equivalent to the aforementioned UI object) is fully created. This prevents the lifecycle after onCreate from potentially attempting to operate on the View before it is initialized, thus avoiding crash issues. Therefore, this solution can reduce the invasiveness to historical code when performing asynchronous loading of the View for historical business code, thereby reducing the cost of modifying historical business code.

[0053] As Figure 4The following is an execution logic diagram of the Fragment life cycle provided by an embodiment of the present invention; Figure 4 In the above, the Fragment life cycle that was previously all executed on the UI thread is optimized so that the onCreateView stage, which is responsible for creating the interface object, is handed over to the IO thread (equivalent to the above-mentioned sub-thread) for processing, thereby reducing the workload of the main thread and avoiding interface jamming problems.

[0054] The second type is applicable to scenarios where Activity / Fragment is used as the page carrier.

[0055] Specifically, after the sub-thread completes the creation of the interface object, it returns to the main thread through the callback update method, so that the main thread generates interface elements based on the interface object and updates the interface elements to the interface corresponding to the target Android application. The specific process may include: creating a listener in the page carrier component in the main thread and registering the listener to the sub-thread; after the sub-thread completes the creation of the interface object, the interface object is called back to the main thread through the listener, so that the page carrier component in the main thread generates interface elements based on the interface object and updates the interface elements to the interface corresponding to the target Android application; where the page carrier component is an Activity component or a Fragment component.

[0056] In specific implementation, a listener is created in the Activity / Fragment and registered to the View asynchronous loading component, which is located in the sub-thread. After the View (interface object) is created, the Activity / Fragment is notified to update the view through the callback, that is, to update the interface elements.

[0057] As Figure 5 The following is a schematic diagram of another loading method for the second service type provided by an embodiment of the present disclosure. Taking the Fragment usage scenario as an example, the Fragment will first display a placeholder image, which can be an image indicating that it is loading, and then initiate an asynchronous loading task in the IO thread. After the IO thread completes the loading of the interface object, the main thread is notified to update the UI through the callback registered in the Fragment. This method loads the interface object in the sub-thread, avoiding the problem of jamming caused by loading the interface object in the main thread. At the same time, this method displays the Activity / Fragment first by setting the placeholder image, avoiding the impact on the life cycle during the startup process of the Activity / Fragment.

[0058] The following embodiments are used to describe specific application examples.

[0059] In a specific embodiment, in an Android application, a scenario where the video playback page can be switched by swiping up and down is supported. In this scenario, the UI objects of each playback page need to be repeatedly created, so this scenario can adopt the interface loading scheme corresponding to the first service type. After adopting the interface loading scheme corresponding to the first service type, it can be seen from the running logs of the Android application that in the same device and the same running scenario, the speed of interface loading and display of this scheme has been significantly improved, that is, this scheme can significantly reduce the time-consuming operations of the main thread and speed up the execution speed of the interface.

[0060] In another specific embodiment, a drawer page is displayed on one side of the home page of the Android application, that is, a page that needs to be actively displayed by the user through a sliding operation. It is invisible to the user when the Android application is started, and the page display priority is not high. The scenario where delaying the initialization of the page will not affect the user experience. Therefore, this method can adopt the interface loading scheme corresponding to the second service type to avoid blocking of the main thread and interface jamming.

[0061] In another specific embodiment, the video Tab of the Android application can be implemented using the ViewPager+Fragment scheme. When ViewPager preloads the Fragments on the left and right sides, the interface asynchronous loading scheme can be adopted. In this way, when switching ViewPager, the interface objects can be created in a child thread, thus effectively reducing the time-consuming tasks of the main thread.

[0062] Corresponding to the above method embodiments, the present disclosure embodiments also provide an interface loading device, which is applied to an electronic device in which a target Android application is installed, as Figure 6 shown. The device includes:

[0063] A service type determination module 60, configured to determine a target service type corresponding to the current interface loading scenario of the target Android application; wherein, the target service type is the first service type or the second service type; the first service type and the second service type perform interface element loading through different loading methods.

[0064] A first interface loading module 61, configured to, when the target service type is the first service type, control the main thread to obtain interface objects from a preset buffer pool, and generate interface elements based on the interface objects and display them on the interface corresponding to the target Android application; wherein, the preset buffer pool is used to store multiple interface objects pre-created by a child thread.

[0065] A second interface loading module 62, configured to, when the target service type is the second service type, after the creation of the interface objects is completed in the child thread, return to the main thread through the callback update method, so that the main thread generates interface elements based on the interface objects and updates the interface elements to the interface corresponding to the target Android application.

[0066] The above interface loading device asynchronously loads the interface object in a child thread when loading the interface, and then switches back to the main thread to perform the update operation of the interface elements, thereby reducing the interface lag phenomenon, avoiding blocking of the main thread, and ensuring the fluency of the Android application. At the same time, this method uses different interface asynchronous loading methods for different business types, so as to better meet the requirements of different business scenarios.

[0067] Further, the above first interface loading module 61 is used to: when the main thread needs an interface object, determine whether there is an available interface object in the preset buffer pool; if so, control the main thread to obtain the interface object from the preset buffer pool, and generate interface elements based on the interface object and display them on the interface corresponding to the target Android application.

[0068] Further, the above first interface loading module 61 is also used to: if there is no available interface object in the preset buffer pool, control the main thread to create an interface object, and generate interface elements based on the interface object and display them on the interface corresponding to the target Android application.

[0069] Further, the above device further includes an object creation module, which is used to: automatically create an interface object through a child thread, and cache the created interface object into the preset buffer pool; when the number of object of the interface objects stored in the preset buffer pool reaches a preset number threshold, control the child thread to stop creating interface objects until the number of object of the interface objects stored in the preset buffer pool is less than the preset number threshold.

[0070] In an alternative embodiment, the above first interface loading module 61 is used to: limit the maximum life cycle of the Fragment component used to create the interface object and interface elements in the main thread to the onCreate stage, so as to avoid the Fragment component executing the life cycle after the onCreate stage before the interface object is created; after the child thread completes the creation of the interface object, and after the child thread completes the creation of the interface object, pass the interface object into the main thread by means of callback update, so that the main thread generates interface elements based on the interface object through the Fragment component, and updates the interface elements to the interface corresponding to the target Android application.

[0071] In another alternative embodiment, the above second interface loading module 62 is used to: create a listener in the page carrier component in the main thread, and register the listener to the child thread; after the child thread completes the creation of the interface object, call back the interface object to the main thread through the listener, so that the page carrier component in the main thread generates interface elements based on the interface object, and updates the interface elements to the interface corresponding to the target Android application; wherein, the page carrier component is an Activity component or a Fragment component.

[0072] Further, the above device further includes an external input module, which is configured to: when the target service type is the second service type, the main thread creates a LayoutInflater through the externally input UiContext.

[0073] The interface loading device provided by the embodiments of the present disclosure has the same implementation principle and the same technical effects as those of the foregoing method embodiments. For the sake of brief description, for the parts not mentioned in the device embodiments, reference may be made to the corresponding content in the foregoing method embodiments.

[0074] Embodiments of the present disclosure also provide an electronic device, as Figure 7 shown. The electronic device includes a processor and a memory. The memory stores machine-executable instructions that can be executed by the processor, and the processor executes the machine-executable instructions to implement the above interface loading method.

[0075] Specifically, the above interface loading method is applied to an electronic device in which a target Android application is installed. Based on this, the above method includes: determining a target service type corresponding to the current interface loading scenario of the target Android application; where the target service type is the first service type or the second service type; the first service type and the second service type load interface elements through different loading methods; when the target service type is the first service type, controlling the main thread to obtain an interface object from a preset buffer pool, and generating interface elements based on the interface object and displaying them on the interface corresponding to the target Android application; where the preset buffer pool is used to store a plurality of interface objects pre-created by a child thread; when the target service type is the second service type, after the child thread completes the creation of the interface object, returning to the main thread through a callback update method, so that the main thread generates interface elements based on the interface object, and updates the interface elements to the interface corresponding to the target Android application.

[0076] In the above interface loading method, after asynchronously loading the interface object in the child thread when loading the interface, it switches back to the main thread to perform the update operation of the interface elements, thereby reducing the interface lag phenomenon, avoiding blocking of the main thread, and ensuring the fluency of the Android application; at the same time, this method uses different interface asynchronous loading methods for different service types, so as to better meet the requirements of different service scenarios.

[0077] In an alternative embodiment, the step of controlling the main thread to obtain an interface object from a preset buffer pool and generating interface elements based on the interface object and displaying them on the interface corresponding to the target Android application includes: when the main thread needs an interface object, determining whether there is an available interface object in the preset buffer pool; if so, controlling the main thread to obtain an interface object from the preset buffer pool, and generating interface elements based on the interface object and displaying them on the interface corresponding to the target Android application.

[0078] In an alternative embodiment, the above method further includes: if there is no available interface object in the preset buffer pool, controlling the main thread to create an interface object, and generating interface elements based on the interface object and displaying them on the interface corresponding to the target Android application.

[0079] In an alternative embodiment, the multiple interface objects stored in the above preset buffer pool are created in the following manner: automatically creating interface objects through a child thread, and caching the created interface objects in the preset buffer pool; when the number of object of the interface objects stored in the preset buffer pool reaches a preset number threshold, controlling the child thread to stop creating interface objects until the number of object of the interface objects stored in the preset buffer pool is less than the preset number threshold.

[0080] In an alternative embodiment, the above step of returning to the main thread by means of callback update after the child thread completes the creation of the interface object, so that the main thread generates interface elements based on the interface object and updates the interface elements to the interface corresponding to the target Android application, includes: restricting the maximum life cycle of the Fragment component used to create the interface object and interface elements in the main thread to the onCreate stage, so as to prevent the Fragment component from executing the life cycle after the onCreate stage before the interface object is created; after the child thread completes the creation of the interface object, and after the child thread completes the creation of the interface object, passing the interface object to the main thread by means of callback update, so that the main thread generates interface elements based on the interface object through the Fragment component and updates the interface elements to the interface corresponding to the target Android application.

[0081] In an alternative embodiment, the above step of returning to the main thread by means of callback update after the child thread completes the creation of the interface object, so that the main thread generates interface elements based on the interface object and updates the interface elements to the interface corresponding to the target Android application, includes: creating a listener in the page carrier component in the main thread and registering the listener to the child thread; after the child thread completes the creation of the interface object, calling back the interface object to the main thread through the listener, so that the page carrier component in the main thread generates interface elements based on the interface object and updates the interface elements to the interface corresponding to the target Android application; wherein, the page carrier component is an Activity component or a Fragment component.

[0082] In an alternative embodiment, the above method further includes: when the target business type is the second business type, the main thread creates a LayoutInflater through an externally passed UiContext.

[0083] Furthermore, Figure 7 The illustrated electronic device further includes a bus 102 and a communication interface 103, and the processor 101, the communication interface 103 and the memory 100 are connected through the bus 102.

[0084] Among them, the memory 100 may include high-speed random access memory (RAM), and may also include non-volatile memory, such as at least one disk memory. The communication connection between this system network element and at least one other network element is realized through at least one communication interface 103 (which can be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. can be used. The bus 102 can be an ISA bus, a PCI bus, an EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of simplicity of representation, Figure 7 only a bidirectional arrow is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0085] The processor 101 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the integrated logic circuit in the hardware of the processor 101 or by instructions in software form. The above-mentioned processor 101 can be a general-purpose processor, including a central processing unit (CPU for short), a network processor (NP for short), etc.; it can also be a digital signal processor (DSP for short), an application specific integrated circuit (ASIC for short), a field-programmable gate array (FPGA for short), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. It can implement or execute the various methods, steps and logic block diagrams disclosed in the embodiments of the present disclosure. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in combination with the embodiments of the present disclosure can be directly embodied as being executed and completed by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. The software module can be located in a mature storage medium in the art such as random access memory, flash memory, read-only memory, programmable read-only memory, or electrically erasable programmable memory, register, etc. This storage medium is located in the memory 100, and the processor 101 reads the information in the memory 100 and combines its hardware to complete the steps of the method in the foregoing embodiments.

[0086] Embodiments of the present disclosure also provide a computer-readable storage medium storing computer-executable instructions which, when called and executed by a processor, cause the processor to implement the above interface editing method. For specific implementation, reference may be made to the method embodiments and will not be elaborated herein.

[0087] Specifically, the above interface loading method is applied to an electronic device installed with a target Android application. Based on this, the method includes: determining a target service type corresponding to the current interface loading scenario of the target Android application, where the target service type is a first service type or a second service type, and the first service type and the second service type load interface elements through different loading methods; when the target service type is the first service type, controlling the main thread to obtain an interface object from a preset buffer pool and generating interface elements based on the interface object to be displayed on the interface corresponding to the target Android application, where the preset buffer pool is used to store multiple interface objects pre-created by a child thread; when the target service type is the second service type, after the child thread completes the creation of the interface object, returning to the main thread in a callback update manner so that the main thread generates interface elements based on the interface object and updates the interface elements to the interface corresponding to the target Android application.

[0088] In the above interface loading method, after asynchronously loading the interface object in the child thread when loading the interface, it then switches back to the main thread to perform the update operation of the interface elements, thereby reducing the interface lag phenomenon, avoiding blocking of the main thread, and ensuring the smoothness of the Android application. At the same time, this method uses different interface asynchronous loading methods for different service types, thus better adapting to the requirements of different service scenarios.

[0089] In an alternative embodiment, the step of controlling the main thread to obtain an interface object from a preset buffer pool and generating interface elements based on the interface object to be displayed on the interface corresponding to the target Android application includes: when the main thread needs an interface object, determining whether there is an available interface object in the preset buffer pool; if so, controlling the main thread to obtain the interface object from the preset buffer pool and generating interface elements based on the interface object to be displayed on the interface corresponding to the target Android application.

[0090] In an alternative embodiment, the method further includes: if there is no available interface object in the preset buffer pool, controlling the main thread to create an interface object and generating interface elements based on the interface object to be displayed on the interface corresponding to the target Android application.

[0091] In an alternative embodiment, the multiple interface objects stored in the preset buffer pool are created in the following manner: automatically create interface objects through a child thread, and cache the created interface objects in the preset buffer pool; when the number of interface objects stored in the preset buffer pool reaches a preset quantity threshold, control the child thread to stop creating interface objects until the number of interface objects stored in the preset buffer pool is less than the preset quantity threshold.

[0092] In an alternative embodiment, the step of, after the child thread finishes creating the interface objects, returning to the main thread in a callback update manner so that the main thread generates interface elements based on the interface objects and updates the interface elements to the interface corresponding to the target Android application includes: restricting the maximum life cycle of the Fragment component used to create the interface objects and interface elements in the main thread to the onCreate stage to prevent the Fragment component from executing the life cycle after the onCreate stage before the interface objects are created; after the child thread finishes creating the interface objects, passing the interface objects to the main thread in a callback update manner so that the main thread generates interface elements based on the interface objects through the Fragment component and updates the interface elements to the interface corresponding to the target Android application.

[0093] In an alternative embodiment, the step of, after the child thread finishes creating the interface objects, returning to the main thread in a callback update manner so that the main thread generates interface elements based on the interface objects and updates the interface elements to the interface corresponding to the target Android application includes: creating a listener in the page carrier component in the main thread and registering the listener to the child thread; after the child thread finishes creating the interface objects, calling back the interface objects to the main thread through the listener so that the page carrier component in the main thread generates interface elements based on the interface objects and updates the interface elements to the interface corresponding to the target Android application; where the page carrier component is an Activity component or a Fragment component.

[0094] In an alternative embodiment, the method further includes: when the target business type is the second business type, the main thread creates a LayoutInflater by externally passing in a UiContext.

[0095] When the above-described functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present disclosure, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a terminal device, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard disks, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), magnetic disks, or optical discs.

[0096] In the description of the present disclosure, it should be noted that the orientation or positional relationship indicated by the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc. is based on the orientation or positional relationship shown in the drawings. It is only for the convenience of describing the present disclosure and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation. Therefore, it should not be construed as a limitation to the present disclosure. In addition, the terms "first", "second", "third" are only used for descriptive purposes and cannot be construed as indicating or implying relative importance.

[0097] Finally, it should be noted that the above-described embodiments are only specific implementation manners of the present disclosure, used to illustrate the technical solutions of the present disclosure, rather than limiting them. The protection scope of the present disclosure is not limited thereto. Although the present disclosure has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that any person skilled in the art within the technical scope disclosed by the present disclosure can still modify the technical solutions described in the foregoing embodiments, or can easily think of changes, or perform equivalent replacements for some of the technical features; and these modifications, changes, or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should all be covered by the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be subject to the protection scope of the claims.

Claims

1. An interface loading method, characterized in that, The method is applied to an electronic device in which a target Android application is installed. The method includes: Determine a target service type corresponding to the current interface loading scenario of the target Android application; wherein, the target service type is a first service type or a second service type; the first service type and the second service type load interface elements through different loading methods; When the target service type is the first service type, control the main thread to obtain an interface object from a preset buffer pool, and generate interface elements based on the interface object and display them on the interface corresponding to the target Android application; wherein, the preset buffer pool is used to store a plurality of interface objects pre-created by a sub-thread; When the target service type is the second service type, after the sub-thread completes the creation of the interface object, return to the main thread through a callback update method, so that the main thread generates interface elements based on the interface object and updates the interface elements to the interface corresponding to the target Android application.

2. The method according to claim 1, wherein The step of controlling the main thread to obtain an interface object from a preset buffer pool and generate interface elements based on the interface object and display them on the interface corresponding to the target Android application includes: When the main thread needs an interface object, determine whether there is an available interface object in the preset buffer pool; If there is, control the main thread to obtain an interface object from the preset buffer pool, and generate interface elements based on the interface object and display them on the interface corresponding to the target Android application.

3. The method according to claim 2, wherein The method further includes: If there is no available interface object in the preset buffer pool, control the main thread to create an interface object, and generate interface elements based on the interface object and display them on the interface corresponding to the target Android application.

4. The method according to claim 2, characterized in that The plurality of interface objects stored in the preset buffer pool are created by the following method: Automatically create interface objects through the sub-thread, and cache the created interface objects into the preset buffer pool; When the number of interface objects stored in the preset buffer pool reaches a preset number threshold, control the sub-thread to stop creating interface objects until the number of interface objects stored in the preset buffer pool is less than the preset number threshold.

5. The method according to claim 1, wherein The step of, after the sub-thread completes the creation of the interface object, returning to the main thread through a callback update method, so that the main thread generates interface elements based on the interface object and updates the interface elements to the interface corresponding to the target Android application includes: Limit the maximum life cycle of the Fragment component used to create the interface object and interface elements in the main thread to the onCreate stage, so as to prevent the Fragment component from executing the life cycle after the onCreate stage before the interface object is created; After the sub-thread completes the creation of the interface object, and after the sub-thread completes the creation of the interface object, pass the interface object into the main thread through a callback update method, so that the main thread generates interface elements based on the interface object through the Fragment component and updates the interface elements to the interface corresponding to the target Android application.

6. The method according to claim 1, wherein After the creation of the interface object in the child thread, return to the main thread through the callback update method, so that the main thread generates interface elements based on the interface object and updates the interface elements to the interface corresponding to the target Android application. The steps include: Create a listener in the page carrier component in the main thread and register the listener to the child thread; After the creation of the interface object in the child thread, callback the interface object to the main thread through the listener, so that the page carrier component in the main thread generates interface elements based on the interface object and updates the interface elements to the interface corresponding to the target Android application; wherein, the page carrier component is an Activity component or a Fragment component.

7. The method according to claim 1, characterized in that, The method further includes: When the target business type is the second business type, the main thread creates a LayoutInflater through an externally passed UiContext.

8. An interface loading device, characterized in that, The device is applied to an electronic device, and the target Android application is installed in the electronic device. The device includes: A business type determination module, configured to determine the target business type corresponding to the current interface loading scenario of the target Android application; wherein, the target business type is the first business type or the second business type; the first business type and the second business type load interface elements through different loading methods; A first interface loading module, configured to, when the target business type is the first business type, control the main thread to obtain an interface object from a preset buffer pool and generate interface elements based on the interface object to be displayed on the interface corresponding to the target Android application; wherein, the preset buffer pool is used to store multiple interface objects pre-created by the child thread; A second interface loading module, configured to, when the target business type is the second business type, return to the main thread through the callback update method after the creation of the interface object in the child thread, so that the main thread generates interface elements based on the interface object and updates the interface elements to the interface corresponding to the target Android application.

9. An electronic device, characterized in that, The electronic device includes a processor and a memory. The memory stores machine-executable instructions that can be executed by the processor. The processor executes the machine-executable instructions to implement the interface loading method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are called and executed by the processor, the computer-executable instructions cause the processor to implement the interface loading method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Method, system, device and storage medium for updating interface based on android system

    CN109254819A

  • Method and device for opening live broadcast room page and computer equipment

    CN110347952A

  • Business module preloading method and device, business module skipping method and device and storage medium

    CN116627521A

  • Fast application card loading method, electronic equipment and storage medium

    CN117130688A

  • Animation playing method and device, electronic equipment and storage medium

    CN118193091A