Lazy Loading Implementation Method, Device, Electronic Device, and Storage Medium

By defining the lazy loading class and target abstract methods of abstract classes, the inheritance and reuse of lazy loading logic is achieved, and the problem that traditional methods are restricted by Android version is solved, improving the applicability and development efficiency of lazy loading.

CN114764484BActive Publication Date: 2025-05-30WUHAN DOUYU NETWORK TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110041366.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-01-13
Publication Date
2025-05-30
Estimated Expiration
2041-01-13

AI Technical Summary

Technical Problem

The traditional lazy loading implementation method is limited by the Android version and is not widely applicable. Developers need to develop separately for different Android versions, which increases the development workload.

Method used

By defining the lazy loading class of the abstract class, the lazy loading logic function is implemented, and the target abstract method is defined in the lazy loading class. At least two target business classes inherit the lazy loading logic function by inheriting the lazy loading class. During the page implementation process, by rewriting the objective functions provided by the system, the target abstract method is passed in to realize the implementation of the same target logic in different business classes.

Benefits of technology

Avoid the lazy loading implementation being restricted by the system version, improve the applicable scenarios of lazy loading implementation, and reduce the workload of developers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114764484B_ABST
    Figure CN114764484B_ABST
Patent Text Reader

Abstract

An embodiment of the present invention discloses a lazy loading implementation method, device, electronic device, and storage medium. The lazy loading implementation method includes: determining a lazy loading class defined as an abstract class to implement the lazy loading logic function, and defining a target abstract method in the lazy loading class to implement the target logic, and at least two target business classes inherit the lazy loading logic function by inheriting the lazy loading class; during the page implementation process, by overriding a target function provided by the system to implement the logic function of the target function when the target function is called back; passing the target abstract method through the overridden target function to implement the implementation of the same target logic in at least two target business classes. The embodiment of the present invention realizes the lazy loading implementation by defining an abstract class and an abstract method, avoiding being restricted by the system version and improving the applicable scenarios of the lazy loading implementation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention relate to the field of communication technologies, and in particular, to a lazy loading implementation method, apparatus, electronic device, and storage medium. Background Art

[0002] Lazy loading can automatically obtain more data when the user scrolls the page, and the newly obtained data will not affect the display of the original data, while minimizing the resource consumption on the server side.

[0003] In traditional lazy loading solutions, the implementation of lazy loading business logic is in the form of defining entity classes, and the implementation of specific logic methods in the entity classes is also in the form of defining entities. The inheritance of entity classes and entity methods is restricted to a certain extent, which affects the access of different loading services. Therefore, the lazy loading in traditional solutions only adapts to the support version of Android and is not applicable under AndroidX. That is, the lazy loading implementation method in traditional solutions has limitations in terms of Android versions, has a narrow scope of application, and requires developers to develop separately for different Android versions, increasing the development workload. Summary of the Invention

[0004] Embodiments of the present invention provide a lazy loading implementation method, apparatus, electronic device, and storage medium to avoid the limitation of lazy loading implementation by the system version and improve the applicable scenarios of lazy loading implementation.

[0005] In a first aspect, embodiments of the present invention provide a lazy loading implementation method, including:

[0006] Determine a lazy loading class defined as an abstract class to implement the lazy loading logic function, and define a target abstract method in the lazy loading class to implement the target logic. At least two target business classes inherit the lazy loading logic function by inheriting the lazy loading class;

[0007] During the page implementation process, rewrite the target function provided by the system to implement the logic function of the target function when the target function is called back;

[0008] Pass the rewritten target function into the target abstract method to implement the implementation of the same target logic in at least two target business classes.

[0009] In a second aspect, embodiments of the present invention further provide a lazy loading implementation apparatus, including:

[0010] An abstract definition module, which is used to determine a lazy loading class defined as an abstract class to implement the lazy loading logic function, and define a target abstract method in the lazy loading class to implement the target logic. At least two target business classes inherit the lazy loading logic function by inheriting the lazy loading class;

[0011] A function overriding module, which is used to override a target function provided by the system during the page implementation process to implement the logic function of the target function when the target function is called back;

[0012] A method passing-in module, which is used to pass in the target abstract method through the overridden target function to implement the implementation of the same target logic in at least two target business classes.

[0013] Thirdly, an embodiment of the present invention further provides an electronic device, including:

[0014] One or more processors;

[0015] A storage device, which is used to store one or more programs,

[0016] When the one or more programs are executed by the one or more processors, the one or more processors implement the lazy loading implementation method as described in any embodiment of the present invention.

[0017] Fourthly, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, it implements the lazy loading implementation method as described in any embodiment of the present invention.

[0018] Based on a lazy loading class defined as an abstract class, the embodiment of the present invention implements the lazy loading logic function and defines a target abstract method in the lazy loading class to implement the target logic. At least two target business classes inherit the lazy loading logic function by inheriting the lazy loading class; during the page implementation process, a target function provided by the system is overridden to implement the logic function of the target function when the target function is called back; the target abstract method is passed in through the overridden target function to implement the implementation of the same target logic in at least two target business classes. By defining abstract classes and abstract methods, the implementation of lazy loading is achieved, avoiding being restricted by the system version and improving the applicable scenarios of lazy loading implementation. Description of the Drawings

[0019] Figure 1 is a flowchart of the lazy loading implementation method in the first embodiment of the present invention;

[0020] Figure 2 is a flowchart of the lazy loading implementation method in the second embodiment of the present invention;

[0021] Figure 3It is a schematic structural diagram of the lazy loading implementation device in the third embodiment of the present invention;

[0022] Figure 4 It is a schematic structural diagram of the electronic device in the fourth embodiment of the present invention. Detailed implementation manners

[0023] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It can be understood that the specific embodiments described herein are only used to explain the present invention, rather than limiting the present invention. In addition, it should be noted that for the convenience of description, only parts related to the present invention are shown in the drawings, rather than all structures.

[0024] Embodiment 1

[0025] Figure 1 It is a flowchart of the lazy loading implementation method in the first embodiment of the present invention. This embodiment is applicable to the situation where lazy loading is implemented under the AndroidX version. This method can be executed by a lazy loading implementation device, which can be implemented in software and / or hardware and can be configured in an electronic device. For example, the electronic device can be a device with communication and computing capabilities such as a background server. As Figure 1 shown, the method specifically includes:

[0026] Step 101: Determine a lazy loading class defined as an abstract class to implement the lazy loading logic function, and define a target abstract method in the lazy loading class to implement the target logic. At least two target business classes inherit the lazy loading logic function by inheriting the lazy loading class.

[0027] Among them, lazy loading refers to the case where there are many static resources on the page to be loaded (such as an e-commerce shopping page). In order to save user traffic and improve page performance, when the user browses to the current resource, the resource is requested and loaded.

[0028] When loading a page, in order to implement the lazy loading function, a lazy loading class is usually defined first, and the lazy loading logic function is implemented in the lazy loading class. In the traditional solution, the definition of the lazy loading class that implements the lazy loading logic function is usually an entity class. However, since the lazy loading function needs to be used in different versions of the Android system, and the specific lazy loading details may be different for different pages, if it is defined as an entity class, it needs to be redefined in each page implementation class, and the applicability is low.

[0029] In an embodiment of the present invention, the lazy loading class is defined as an abstract class to enhance the constraint behavior on the implementation classes of specific services. And defining the lazy loading class as an abstract class facilitates inheritance by business classes. Here, each business class is used for different types of page loading. By implementing the lazy loading logic function in the abstract class, after the business class inherits the lazy loading class, it dynamically inherits the lazy loading logic function, reducing the success of service access and greatly improving the development efficiency, and avoiding the need for developers to develop a complete set of lazy loading logics for each business class. Exemplarily, the definition of the specific class of the lazy loading class is as follows: abstract class LazyFragmentAndroidX : Fragment(). Here, abstract indicates that this class is defined as an abstract class, LazyFragmentAndroidX represents the name of the lazy loading class, and Fragment represents the name of a function in the lazy loading class.

[0030] Since some of the logic functions in the lazy loading logic function will vary in each service, in order to increase the applicable scope of this part of the logic function, the target logic is implemented by defining target abstract methods for this part of the logic function. So that when different target business classes inherit the lazy loading class, the target abstract method can be specifically described according to their own logics, and at the same time, different target business classes inherit the logic functions in the lazy loading class by inheriting the lazy loading class. The applicable scope of the lazy loading class is increased.

[0031] In a feasible embodiment, the target abstract methods include a method for obtaining the page layout ID, a method for view initialization, and a method for lazy loading initialization logic; among them, the method for obtaining the page layout ID is used to obtain the layout ID information of the current page, the method for view initialization is used to design the view initialization logic, and the method for lazy loading initialization logic is used to design the initialization business logic of lazy loading.

[0032] Since there are differences in the logics in the methods for obtaining the layout ID information of the current page for different types of pages; similarly, there are also differences in the view initialization logic and the initialization business logic of lazy loading for different types of pages, so abstract methods are defined for these logics for subsequent respective business implementations by different business implementation classes.

[0033] Exemplarily, the specific definition of the method for obtaining the page layout ID is as follows: abstract fun getLayoutId(): Int. The name of this abstract method is getLayoutId, and the return value is a data of Int type, where the data of Int type is the layout ID information of the current page. The specific function definition of the view initialization method is as follows: abstract fun initView(view: View, savedInstanceState: Bundle?). The specific definition of the lazy loading initialization logic method is as follows: abstract fun lazyInit(). Among them, abstract indicates that this method is defined as an abstract method, getLayoutId represents the name of the method for obtaining the page layout ID, initView represents the name of the view initialization method, and lazyInit represents the name of the lazy loading initialization logic method. For the initView method, two parameters need to be input into the function. The type of the first parameter is the View type defined within the view class, and the second parameter is the Bundle type defined within the savedInstanceState class. When specifically defining the business class, the business class inherits the lazy loading class, and in the business class, the specific definition of this target abstract method is carried out, so that when the target abstract method is called, the specific implementation of the target abstract method is achieved through the subclass, that is, the method with the same name in the inherited business class. Thus, the same target logic function for different businesses is achieved.

[0034] Step 102, during the page implementation process, by overriding the target function provided by the system, the logical function of the target function is implemented when the target function is called back.

[0035] Among them, the page implementation process refers to the process from the start of page loading to the destruction after the page loading is completed. During the page implementation process, the page will call back the relevant target functions provided by the Android system. However, since the implementation logic functions in these relevant target functions will be different from the actual requirements, in the embodiments of the present invention, the relevant target functions provided by the system are overridden to achieve specific logical functions when these target functions are called back on the page. Specifically, the target functions called back by the page are determined according to the stage of the page implementation process.

[0036] Step 103, pass the target abstract method through the overridden target function to achieve the implementation of the same target logic in at least two target business classes.

[0037] Since the overridden target function is used to implement a specific business logic method, a target abstract method is passed into the overridden target function, and the passed target abstract method is determined according to the stage of the page implementation process. The specific implementation of the target abstract method passed into the overridden target function is implemented by its subclass, that is, the corresponding business inheritance class, so that the same logical function is called in different business classes.

[0038] In a feasible embodiment, the method further includes: defining a globally dynamically obtained print label identification variable to facilitate subsequent inherited business classes to print log information when outputting logs. Exemplarily, the specific print label identification variable TAG is defined as follows: private val TAG = this.javaClass.simpleName.

[0039] In the traditional solution, the print label identification is a string. In the embodiment of the present invention, the print label identification is a dynamically obtained variable. Among them, private indicates that the print label identification variable is of private type and is only for members in the lazy loading class to call. val indicates the data type of the print label identification variable. TAG indicates the name of the print label identification variable. this is the current class. javaClass is an object created in the current class, and simplename is a variable in this object. Since this represents the current object, for different inherited business classes, it represents the object of the inherited business class. Therefore, when the subsequent inherited class accesses TAG, the output is the class name of the current class, which can greatly improve the efficiency and performance of log output during log printing and debugging.

[0040] The embodiment of the present invention is based on a lazy loading class defined as an abstract class to implement the lazy loading logic function and define a target abstract method in the lazy loading class to implement the target logic. At least two target business classes inherit the lazy loading logic function by inheriting the lazy loading class; during the page implementation process, the target function provided by the system is overridden to implement the logic function of the target function when the target function is called back; the target abstract method is passed into the overridden target function to implement the implementation of the same target logic in at least two target business classes. By defining the abstract class and the abstract method, the lazy loading implementation is avoided from being restricted by the system version, and the applicable scenarios of the lazy loading implementation are improved.

[0041] Embodiment 2

[0042] Figure 2 It is a flowchart of the lazy loading implementation method in Embodiment 2 of the present invention. Embodiment 2 is further optimized on the basis of Embodiment 1. As Figure 2 shown, the method includes:

[0043] Step 201: Determine the lazy-loading class defined as an abstract class to implement the lazy-loading logic function, and define the target abstract method in the lazy-loading class to implement the target logic. At least two target business classes inherit the lazy-loading logic function by inheriting the lazy-loading class.

[0044] Step 202: When the page is loaded, override the onCreateView function provided by the system to implement the specific page layout loading logic by calling back the onCreateView function when the page is loaded.

[0045] Among them, page loading is the initial process in the page implementation process. When implementing page lazy loading, page loading will be performed first. When the page is loaded, the onCreateView function provided by the system will be called back. This function is a function provided by the system to load the page. Since in the embodiments of the present invention, the page loading logics for different pages are different and need to be determined according to the layout information of the current page, it is necessary to override this onCreateView function to implement the specific page layout loading logic.

[0046] Exemplarily, the onCreateView function will be called back first when the page is loaded. Therefore, the specific business logic method is implemented by overriding this function. The specific overriding method is as follows: override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {}. Among them, override indicates that the onCreateView function is an overridden function. The input parameters of this overridden function are LayoutInflater defined in the inflater class, ViewGroup type defined in the container class, and Bundle type defined in the savedInstanceState class. The input of the onCreateView function is not limited in the embodiments of the present invention and can be determined according to the specific implementation logic and the definition of the foregoing function. This overriding example is only one specific page loading overriding method, and the specific parameter passing in the overridden function is not limited in the embodiments of the present invention.

[0047] Step 203: In the overridden onCreateView function, pass in the method for obtaining the page layout ID to implement loading the method for obtaining the page layout ID in the target business class to return the layout ID information of the current page; the specific implementation of the method for obtaining the page layout ID is achieved through the inheritance function in at least two target business classes to implement the same target logic in at least two target business classes.

[0048] Since the overridden onCreateView function is used to determine the specific logic for page loading, the method for obtaining the page layout ID is passed into this overridden function to load and obtain the layout ID information of the current page by returning the method for obtaining the page layout ID in the target business class, and specific page loading is performed based on the layout ID information of the current page.

[0049] Exemplarily, based on the above example, the loading of the page layout is achieved by calling the inflate method in the inflater object in the onCreateView function. The specific function call is as follows: return inflater.inflate(getLayoutId(), container, false). Among them, this function represents calling the inflate function in the inflater class. This function has three formal parameters passed in. One is the layout ID returned by the target abstract method passing in the method for obtaining the page layout ID getLayoutId(), one is container, and one is false.

[0050] Through the inflater.inflate(getLayoutId(), container, false) method, the layout ID information returned by the target abstract method is loaded in the form of passing in a target abstract method for obtaining the page layout ID method getLayoutId(). The specific implementation of this target abstract method is implemented by the subclass, that is, the business inheritance class, realizing the same loading logic function for different services.

[0051] Step 204, after the page loading is completed, by overriding the onViewCreated function provided by the system, the onViewCreated function is called back when the page loading is completed to implement the specific view initialization logic.

[0052] Among them, the completion of page loading is a process after page loading in the page implementation process. When lazy page loading is implemented, after the page loading is completed, if the page needs to perform view initialization, the onViewCreated function provided by the system will be called back. This function is a function provided by the system for initializing the page view. Since in the embodiments of the present invention, the view initialization logics for different pages are different and need to be determined according to the specific conditions of the current page, it is necessary to override this onViewCreated function to implement the specific page view initialization logic.

[0053] Exemplarily, after the page is loaded, the system will call back the onViewCreated function. Therefore, by overriding this function, the special initialization function of some views can be processed in this function. The method of overriding the system's onViewCreated is as follows: override fun onViewCreated(view:View, savedInstanceState:Bundle?){}. Among them, override indicates that the onViewCreated function is an overridden function. The inputs of this overridden function are the View variable defined in the view class and the Bundle type defined in the savedInstanceState class. This overriding example is only one specific view initialization method, and in the embodiments of the present invention, the specific parameter passing in the overridden function is not restricted.

[0054] Step 205: In the overridden onViewCreated function, pass in the view initialization method to obtain the specific view initialization design logic in the view initialization method in the target business class; among them, the specific implementation of the view initialization method is achieved through the inheritance function in at least two target business classes to achieve the implementation of the same target logic in at least two target business classes.

[0055] Since the overridden onViewCreated function is used to determine the specific logic for initializing the page view, the view initialization method is passed in this overridden function to obtain the specific view initialization design logic in the view initialization method in the target business class.

[0056] Exemplarily, on the basis of the above example, the specific view initialization logic function is implemented by calling the view initialization method initView in the onViewCreated function. Since the initView method is an abstract function, when this method is called, the system will call its implementation class, and its implementation class is the business class that inherits this abstract class, that is, the view initialization method of the specific business, so as to achieve the goal of the unified view initialization method for the overall business.

[0057] Step 206: When the page is visible, by overriding the onResume function provided by the system, the onResume function is called back when the page is visible to implement the page loading and visibility logic.

[0058] Among them, the page visible stage occurs after the page view initialization is completed during the page implementation process. When implementing page lazy loading, after the page view initialization is completed, the page needs to perform lazy loading initialization, that is, when the page is visible, the onResume function provided by the system will be called back. This function is provided by the system to handle the visibility of the page. Since in the embodiments of the present invention, when handling the visibility of different pages, the lazy loading initialization logic is different and needs to be determined according to the specific situation of the current page, it is necessary to override the onResume function to implement the lazy loading initialization when the specific page is visible and make the page visible.

[0059] Exemplarily, after the page view initialization is completed, the system will call back the onResume function. Therefore, by overriding this function, the logic for lazy loading initialization when the page is visible can be processed in this function. When the system page is about to be visible, the onResume method will be called back. By overriding this method, a lazy loading logic determination is made when the page is visible. The specific overriding method is as follows: override fun onResume() {}.

[0060] Step 207: In the overridden onResume function, pass in the lazy loading initialization logic method to obtain the specific lazy loading initialization design logic in the lazy loading initialization logic method in the target business class; among them, the specific implementation of the lazy loading initialization logic method is achieved through the inheritance function in at least two target business classes to implement the same target logic in at least two target business classes.

[0061] Since the overridden onResume function is used to make the page visible, it is necessary to determine the initialization logic of lazy loading in this function. Pass in the lazy loading initialization logic method in the overridden onResume function to obtain the specific lazy loading initialization design logic in the lazy loading initialization logic method in the target business class.

[0062] Exemplarily, on the basis of the above example, in the onResume function, by calling the lazy loading initialization logic method, that is, the lazyInit() method, the lazy loading initialization logic determination function in the implementation class is triggered, thereby implementing the lazy loading initialization logic of the business class.

[0063] In a feasible embodiment, the method further includes:

[0064] Define a global variable to mark whether the current page is loaded;

[0065] Correspondingly, in the overridden onResume function, passing in the lazy loading initialization logic method includes:

[0066] In the overridden onResume function, first, it is determined whether the current page is loaded through a global variable, and whether the current page is in a visible state is determined by calling the system's visible state judgment function;

[0067] If the current page is not loaded and is in an invisible state, the lazy loading initialization logic method is passed in, and the global variable is modified after the lazy loading initialization logic method call is completed to mark that the current page has been loaded.

[0068] To avoid reloading a page that has already been loaded, a global variable is defined in the embodiment of the present invention to mark whether the current page is loaded. Exemplarily, the global variable is specifically defined as follows: private var isLoaded = false, where initializing this global variable to false indicates that the initial state is not loaded.

[0069] Specifically, in the overridden onResume function, if the current page has already been loaded, there is no need to perform the lazy loading initialization logic determination process. Only when the current page has not been loaded, the subsequent loading process is carried out. Optionally, in addition to judging whether the current page is loaded through the global variable, it is also possible to determine the subsequent loading process by using the system-provided method to judge whether the current page is in a visible state. If the current page is in a visible state, there is no need to perform the subsequent loading process.

[0070] Exemplarily, in the overridden onResume function, first, it is judged whether the current page has been loaded through the judgment condition: if (!isLoaded &&!isHidden), and whether the current page is in a visible state is judged by calling the system's isHidden method. If the current page has neither been loaded nor is in a visible state, the subsequent loading process is executed at this time, otherwise, no subsequent lazy loading initialization logic processing is performed.

[0071] If the judgment condition is satisfied, it is considered that the current page is loaded for the first time. At this time, the specific lazy loading initialization logic function in its implementation class can be triggered by calling the target abstract method lazyInit() method, thus realizing the lazy loading initialization logic of the business class.

[0072] After the lazy loading initialization logic method call is completed, the isLoaded variable is set to true by calling the method isLoaded = true, so that when the page is visible for the second time, since the above judgment condition cannot be established, the page that has already been loaded will not be triggered for a second load, thus effectively avoiding the problem of the page being repeatedly loaded and greatly improving the page loading efficiency and page reuse rate.

[0073] Step 208: When the page view is destroyed, override the onDestroyView function provided by the system to call back the onDestroyView function when the page view is destroyed to implement the data cleaning operation.

[0074] In the overridden onDestroyView function, modify the global variable to mark that the current page is not loaded.

[0075] Among them, the destruction of the page view occurs after the lazy loading initialization of the page view is completed during the page implementation process. When the page view is destroyed, the onDestroyView function provided by the system will be called back. This function is a function provided by the system for destroying the page. In the embodiments of the present invention, the data cleaning operations required for destroying different pages are different and need to be determined according to the specific situation of the current page. Therefore, it is necessary to override the onDestroyView function to call back the onDestroyView function when the page view is destroyed to implement the data cleaning operation.

[0076] Exemplarily, when the view is destroyed, the system will call back the onDestroyView function, and the data cleaning operation is implemented by overriding this function. The specific overriding method is as follows: override fun onDestroyView() {}. Among them, override indicates that the onDestroyView function is an overridden function.

[0077] Since after the page is destroyed, it is necessary to modify the global variable that marks whether the current page is loaded, so that the global variable is set to the unloaded state after the page is destroyed, effectively indicating the problem of the empty view when the page view is loaded next time. The above page implementation process will further execute, avoiding possible crash problems after the view is destroyed, and greatly improving the stability of the program. Exemplarily, in this overridden onDestroyView function, the variable value of isLoaded is reset to the initial value by calling the method isLoaded = false.

[0078] The embodiments of the present invention are based on a lazy loading class defined as an abstract class to implement the lazy loading logic function and define a target abstract method in the lazy loading class to implement the target logic. At least two target business classes inherit the lazy loading logic function by inheriting the lazy loading class; during the page implementation process, override the target function provided by the system to implement the logic function of the target function when the target function is called back; pass the target abstract method into the overridden target function to implement the implementation of the same target logic in at least two target business classes. By defining the abstract class and the abstract method, the implementation of lazy loading is avoided from being restricted by the system version, and the applicable scenarios of lazy loading implementation are improved.

[0079] Embodiment 3

[0080] Figure 3 is a schematic structural diagram of the lazy loading implementation device in Embodiment 3 of the present invention. This embodiment is applicable to the situation where lazy loading is implemented under the AndroidX version. As Figure 3 shown, the device includes:

[0081] An abstract definition module 310, which is used to determine the lazy loading class defined as an abstract class to implement the lazy loading logic function, and define a target abstract method in the lazy loading class to implement the target logic. At least two target business classes inherit the lazy loading logic function by inheriting the lazy loading class;

[0082] A function overriding module 320, which is used to override the target function provided by the system during the page implementation process to implement the logic function of the target function when the target function is called back;

[0083] A method passing-in module 330, which is used to pass in the target abstract method through the overridden target function to implement the implementation of the same target logic in at least two target business classes.

[0084] Based on the lazy loading class defined as an abstract class, this embodiment of the present invention implements the lazy loading logic function and defines a target abstract method in the lazy loading class to implement the target logic. At least two target business classes inherit the lazy loading logic function by inheriting the lazy loading class; during the page implementation process, the target function provided by the system is overridden to implement the logic function of the target function when the target function is called back; the target abstract method is passed in through the overridden target function to implement the implementation of the same target logic in at least two target business classes. By defining the abstract class and the abstract method, the lazy loading implementation is avoided from being restricted by the system version, and the applicable scenarios of the lazy loading implementation are improved.

[0085] Optionally, the target abstract method includes a method for obtaining the page layout ID, a method for initializing the view, and a method for initializing the lazy loading logic; wherein, the method for obtaining the page layout ID is used to obtain the layout ID information of the current page, the method for initializing the view is used to design the view initialization logic, and the method for initializing the lazy loading logic is used to design the initialization business logic of the lazy loading.

[0086] Optionally, the function overriding module includes a loading function overriding unit, which is used for:

[0087] When the page is loaded, override the onCreateView function provided by the system to implement the specific page layout loading logic when the onCreateView function is called back during page loading;

[0088] Correspondingly, the method passing-in module includes a method loading unit for:

[0089] In the overridden onCreateView function, pass in the method for obtaining the page layout ID to load the layout ID information of the current page returned by the method for obtaining the page layout ID in the target business class; wherein, the specific implementation of the method for obtaining the page layout ID is achieved through the inheritance function in at least two target business classes to implement the same target logic in at least two target business classes.

[0090] Optionally, the function overriding module includes a view initialization function overriding unit for:

[0091] After the page is loaded, override the onViewCreated function provided by the system to call back the onViewCreated function when the page is loaded to implement the specific view initialization logic.

[0092] Correspondingly, the method passing-in module includes a view initialization method passing-in unit for:

[0093] In the overridden onViewCreated function, pass in the view initialization method to obtain the specific view initialization design logic in the view initialization method in the target business class; wherein, the specific implementation of the view initialization method is achieved through the inheritance function in at least two target business classes to implement the same target logic in at least two target business classes.

[0094] Optionally, the function overriding module includes a page loading function overriding unit for:

[0095] When the page is visible, override the onResume function provided by the system to call back the onResume function when the page is visible to implement the page loading and visibility logic.

[0096] Correspondingly, the method passing-in module includes a lazy loading initialization method passing-in unit for:

[0097] In the overridden onResume function, pass in the lazy loading initialization logic method to obtain the specific lazy loading initialization design logic in the lazy loading initialization logic method in the target business class; wherein, the specific implementation of the lazy loading initialization logic method is achieved through the inheritance function in at least two target business classes to implement the same target logic in at least two target business classes.

[0098] Optionally, the method further includes:

[0099] Define a global variable to mark whether the current page is loaded.

[0100] Correspondingly, the lazy loading initialization method passes in the unit, specifically for:

[0101] In the overridden onResume function, first, it is determined whether the current page is loaded through the global variable, and it is determined whether the current page is in a visible state by calling the system's visible state judgment function;

[0102] If the current page is not loaded and is in an invisible state, the lazy loading initialization logic method is passed in, and after the call of the lazy loading initialization logic method is completed, the global variable is modified to mark that the current page has been loaded.

[0103] Optionally, the function overriding module includes a view destruction function overriding unit, which is used for:

[0104] When the page view is destroyed, by overriding the onDestroyView function provided by the system, the onDestroyView function is called back when the page view is destroyed to implement the data cleaning operation;

[0105] In the overridden onDestroyView function, the global variable is modified to mark that the current page is not loaded.

[0106] The lazy loading implementation device provided by the embodiments of the present invention can execute the lazy loading implementation method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects for executing the lazy loading implementation method.

[0107] Embodiment 4

[0108] Figure 4 It is a schematic structural diagram of an electronic device provided by Embodiment 4 of the present invention. Figure 4 It shows a block diagram of an exemplary electronic device 12 suitable for implementing the embodiments of the present invention. Figure 4 The shown electronic device 12 is only an example and should not bring any limitation to the functions and usage scope of the embodiments of the present invention.

[0109] As Figure 4 shown, the electronic device 12 is presented in the form of a general-purpose computing device. The components of the electronic device 12 may include but are not limited to: one or more processors or processing units 16, a system storage device 28, and a bus 18 connecting different system components (including the system storage device 28 and the processing unit 16).

[0110] Bus 18 represents one or more of several types of bus architectures, including a memory bus or memory controller, a peripheral bus, an Accelerated Graphics Port, a processor bus, or a local bus using any of a variety of bus architectures. By way of example, such architectures include, but are not limited to, Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MAC) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.

[0111] Electronic device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by electronic device 12, including both volatile and nonvolatile media, removable and non-removable media.

[0112] System memory 28 can include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. Electronic device 12 may further include other removable / non-removable, volatile / nonvolatile computer system storage media. By way of example only, storage system 34 can be provided for reading from and writing to non-removable, nonvolatile magnetic media ( Figure 4 not shown and typically called a "hard disk drive"). Although Figure 4 not shown in the figures, a disk drive for reading from and writing to a removable nonvolatile disk (e.g., a "floppy disk"), and an optical disk drive for reading from and writing to a removable nonvolatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) can be provided. In these cases, each drive can be connected to bus 18 by one or more data media interfaces. Storage device 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to carry out the functions of the embodiments of the present invention.

[0113] A program / utility 40 having a set (at least one) of program modules 42 can be stored, for example, in storage device 28. Such program modules 42 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data, and an implementation of a network environment may be included in some or all of these examples. Program modules 42 generally carry out the functions and / or methods of the embodiments described herein.

[0114] The electronic device 12 can also communicate with one or more external devices 14 (such as a keyboard, a pointing device, a display 24, etc.), and can also communicate with one or more devices that enable a user to interact with the device 12, and / or communicate with any device that enables the device 12 to communicate with one or more other computing devices (such as a network card, a modem, etc.). Such communication can be carried out through the input / output (I / O) interface 22. Moreover, the electronic device 12 can also communicate with one or more networks (such as a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through the network adapter 20. As Figure 4 shown, the network adapter 20 communicates with other modules of the electronic device 12 through the bus 18. It should be understood that although Figure 4 not shown in the figure, other hardware and / or software modules can be used in combination with the electronic device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc.

[0115] The processing unit 16 executes various functional applications and data processing by running programs stored in the system storage device 28, for example, implementing the lazy loading implementation method provided by the embodiments of the present invention, including:

[0116] Determine the lazy loading class defined as an abstract class to implement the lazy loading logic function, and define a target abstract method in the lazy loading class to implement the target logic. At least two target business classes inherit the lazy loading logic function by inheriting the lazy loading class;

[0117] During the page implementation process, by overriding the target function provided by the system, the logic function of the target function is implemented when the target function is called back;

[0118] Pass the target abstract method through the overridden target function to implement the implementation of the same target logic in at least two target business classes.

[0119] Embodiment Five

[0120] Embodiment Five of the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the program is executed by a processor, the lazy loading implementation method provided by the embodiments of the present invention is implemented, including:

[0121] Determine the lazy loading class defined as an abstract class to implement the lazy loading logic function, and define a target abstract method in the lazy loading class to implement the target logic. At least two target business classes inherit the lazy loading logic function by inheriting the lazy loading class;

[0122] During the page implementation process, the target function provided by the system is overridden to implement the logical function of the target function when the target function is called back.

[0123] The overridden target function is passed into the target abstract method to implement the realization of the same target logic in at least two target business classes.

[0124] The computer storage medium of the embodiments of the present invention may adopt any combination of one or more computer-readable media. The computer-readable media may be computer-readable signal media or computer-readable storage media. The computer-readable storage media may be, for example, but not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or components, or any combination of the above. More specific examples (non-exhaustive list) of the computer-readable storage media include: electrical connections with one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above. In this document, the computer-readable storage media may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, device, or component.

[0125] The computer-readable signal media may include data signals propagated in a baseband or as part of a carrier wave, which carry computer-readable program codes. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal media may also be any computer-readable media other than the computer-readable storage media, which can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, device, or component.

[0126] The program codes contained on the computer-readable media may be transmitted by any appropriate medium, including but not limited to wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0127] Computer program code for performing the operations of the present invention may be written in one or more programming languages or combinations thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and also including conventional procedural programming languages such as the "C" language or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, executed as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network including a local area network (LAN) or a wide area network (WAN), or, may be connected to an external computer (e.g., through the Internet using an Internet service provider).

[0128] Note that the above is only the preferred embodiment of the present invention and the technical principles applied. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and various obvious changes, re-adjustments, and substitutions can be made by those skilled in the art without departing from the protection scope of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments only. Without departing from the concept of the present invention, more other equivalent embodiments may be included, and the scope of the present invention is determined by the scope of the appended claims.

Claims

1. A lazy loading implementation method, characterized in that, it includes: Determine a lazy loading class defined as an abstract class to implement the lazy loading logic function, and define a target abstract method in the lazy loading class to implement the target logic. At least two target business classes inherit the lazy loading logic function by inheriting the lazy loading class; During the page implementation process, rewrite the target function provided by the system to implement the logic function of the target function when the target function is called back; Pass the target abstract method through the rewritten target function to implement the implementation of the same target logic in at least two target business classes; Among them, the target abstract method includes a method for obtaining the page layout ID, a view initialization method, and a lazy loading initialization logic method; among them, the method for obtaining the page layout ID is used to obtain the layout ID information of the current page, the view initialization method is used to design the view initialization logic, and the lazy loading initialization logic method is used to design the initialization business logic of lazy loading; The method further includes: Define a globally dynamically obtained print label identification variable so that the subsequent inherited business classes can print log information when outputting logs; The process of rewriting the target function provided by the system during the page implementation process to implement the logic function of the target function when the target function is called back includes: When the page is loaded, rewrite the onCreateView function provided by the system to implement the specific page layout loading logic when the onCreateView function is called back during page loading; Correspondingly, passing the target abstract method through the rewritten target function to implement the implementation of the same target logic in at least two target business classes includes: In the rewritten onCreateView function, pass in the method for obtaining the page layout ID to implement loading the layout ID information of the current page returned by the method for obtaining the page layout ID in the target business class; among them, the specific implementation of the method for obtaining the page layout ID is achieved through the inheritance function in at least two target business classes to implement the implementation of the same target logic in at least two target business classes; Passing in the method for obtaining the page layout ID in the rewritten onCreateView function to implement loading the layout ID information of the current page returned by the method for obtaining the page layout ID in the target business class includes: In the onCreateView function, call the inflate method in the infalter object to implement the loading of the page layout; The process of rewriting the target function provided by the system during the page implementation process to implement the logic function of the target function when the target function is called back further includes: After the page is loaded, rewrite the onViewCreated function provided by the system to implement the specific view initialization logic when the onViewCreated function is called back when the page is loaded; Correspondingly, passing the target abstract method through the rewritten target function to implement the implementation of the same target logic in at least two target business classes includes: In the overridden onViewCreated function, pass in the view initialization method to obtain the specific view initialization design logic in the target business class; wherein, the specific implementation of the view initialization method is achieved through the inheritance function in at least two target business classes to implement the same target logic in at least two target business classes; The step of passing in the view initialization method in the overridden onViewCreated function to obtain the specific view initialization design logic in the target business class includes: In the onViewCreated function, call the view initialization initView to implement the specific view initialization design logic.

2. The method according to claim 1, wherein, During the page implementation process, override the target function provided by the system to implement the logical function of the target function when the target function is called, including: When the page is visible, override the onResume function provided by the system to implement the page loading and visibility logic by calling the onResume function when the page is visible; Correspondingly, pass in the target abstract method through the overridden target function to implement the same target logic in at least two target business classes, including: In the overridden onResume function, pass in the lazy loading initialization logic method to obtain the specific lazy loading initialization design logic in the lazy loading initialization logic method in the target business class; wherein, the specific implementation of the lazy loading initialization logic method is achieved through the inheritance function in at least two target business classes to implement the same target logic in at least two target business classes.

3. The method according to claim 2, wherein, The method further includes: Define a global variable to mark whether the current page is loaded; Correspondingly, passing in the lazy loading initialization logic method in the overridden onResume function includes: In the overridden onResume function, first determine whether the current page is loaded through the global variable, and determine whether the current page is in a visible state by calling the system's visible state judgment function; If the current page is not loaded and is in an invisible state, pass in the lazy loading initialization logic method, and modify the global variable to mark that the current page has been loaded after the lazy loading initialization logic method is called.

4. The method according to claim 3, wherein, During the page implementation process, override the target function provided by the system to implement the logical function of the target function when the target function is called, including: When the page view is destroyed, override the onDestroyView function provided by the system to implement the data cleaning operation by calling the onDestroyView function when the page view is destroyed; In the overridden onDestroyView function, modify the global variable to mark that the current page is not loaded.

5. A lazy loading implementation device, wherein, including: An abstract definition module is used to determine lazy loading classes defined as abstract classes to implement lazy loading logic functions, and define target abstract methods in the lazy loading classes to implement target logic. At least two target business classes inherit the lazy loading logic functions by inheriting the lazy loading classes; A function overriding module is used to, during the page implementation process, override a target function provided by the system to implement the logic function of the target function when the target function is called back; A method passing-in module is used to pass in the target abstract method through the overridden target function to implement the implementation of the same target logic in at least two target business classes; Among them, the target abstract methods include a method for obtaining a page layout ID, a view initialization method, and a lazy loading initialization logic method. Among them, the method for obtaining a page layout ID is used to obtain the layout ID information of the current page, the view initialization method is used to design view initialization logic, and the lazy loading initialization logic method is used to design the initialization business logic of lazy loading; The device is further used for: Defining a globally dynamically obtained print label identification variable so that subsequent inherited business classes can print log information when performing log output; The function overriding module includes: A loading function overriding unit is used for: when the page is loaded, overriding the onCreateView function provided by the system to implement specific page layout loading logic when the onCreateView function is called back during page loading; Correspondingly, the method passing-in module includes: A loading method passing-in unit is used for: in the overridden onCreateView function, passing in the method for obtaining a page layout ID to implement loading the method for obtaining a page layout ID in the target business class to return the layout ID information of the current page. Among them, the specific implementation of the method for obtaining a page layout ID is achieved through the inheritance function in at least two target business classes to implement the implementation of the same target logic in at least two target business classes; The passing in the method for obtaining a page layout ID in the overridden onCreateView function to implement loading the method for obtaining a page layout ID in the target business class to return the layout ID information of the current page includes: Implementing the loading of the page layout by calling the inflate method in the infalter object in the onCreateView function; The function overriding module further includes: A view initialization function overriding unit is used for: after the page is loaded, overriding the onViewCreated function provided by the system to implement specific view initialization logic when the onViewCreated function is called back when the page is loaded; Correspondingly, the method passing-in module further includes: The view initialization method is passed into the unit for: in the overridden onViewCreated function, passing in the view initialization method to obtain the specific view initialization design logic in the view initialization method in the target business class; wherein, the specific implementation of the view initialization method is achieved through the inheritance function in at least two target business classes to implement the same target logic in at least two target business classes; The step of passing in the view initialization method in the overridden onViewCreated function to obtain the specific view initialization design logic in the view initialization method in the target business class includes: In the onViewCreated function, calling the view initialization initView to implement the specific view initialization design logic.

6. An electronic device, Characterized in that, Comprising: One or more processors; A storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, enabling the one or more processors to implement the lazy loading implementation method as described in any one of claims 1-4.

7. A computer-readable storage medium, having a computer program stored thereon, Characterized in that, When the program is executed by a processor, it implements the lazy loading implementation method as described in any one of claims 1-4.