CN114764484A - Lazy loading implementation method and device, electronic equipment and storage medium - Google Patents
Lazy loading implementation method and device, electronic equipment and storage medium Download PDFInfo
- Publication number
- CN114764484A CN114764484A CN202110041366.3A CN202110041366A CN114764484A CN 114764484 A CN114764484 A CN 114764484A CN 202110041366 A CN202110041366 A CN 202110041366A CN 114764484 A CN114764484 A CN 114764484A
- Authority
- CN
- China
- Prior art keywords
- function
- target
- logic
- page
- lazy loading
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 208
- 238000011068 loading method Methods 0.000 title claims abstract description 191
- 230000006870 function Effects 0.000 claims description 255
- 238000011423 initialization method Methods 0.000 claims description 26
- OKTJSMMVPCPJKN-UHFFFAOYSA-N Carbon Chemical compound [C] OKTJSMMVPCPJKN-UHFFFAOYSA-N 0.000 claims description 19
- 229910052799 carbon Inorganic materials 0.000 claims description 19
- 238000013461 design Methods 0.000 claims description 8
- 238000004140 cleaning Methods 0.000 claims description 6
- 238000004590 computer program Methods 0.000 claims description 6
- 238000012545 processing Methods 0.000 description 9
- 230000003287 optical effect Effects 0.000 description 6
- 238000010586 diagram Methods 0.000 description 5
- 238000004891 communication Methods 0.000 description 3
- 230000008676 import Effects 0.000 description 3
- 230000001960 triggered effect Effects 0.000 description 3
- 230000003044 adaptive effect Effects 0.000 description 2
- 230000006378 damage Effects 0.000 description 2
- 238000011161 development Methods 0.000 description 2
- 239000012634 fragment Substances 0.000 description 2
- 239000013307 optical fiber Substances 0.000 description 2
- 230000002093 peripheral effect Effects 0.000 description 2
- 230000000644 propagated effect Effects 0.000 description 2
- 238000003491 array Methods 0.000 description 1
- 230000006399 behavior Effects 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000008707 rearrangement Effects 0.000 description 1
- 239000004065 semiconductor Substances 0.000 description 1
- 230000003068 static effect Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/95—Retrieval from the web
- G06F16/957—Browsing optimisation, e.g. caching or content distillation
- G06F16/9574—Browsing optimisation, e.g. caching or content distillation of access to content, e.g. by caching
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/445—Program loading or initiating
- G06F9/44521—Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Databases & Information Systems (AREA)
- Data Mining & Analysis (AREA)
- Stored Programmes (AREA)
Abstract
The embodiment of the invention discloses a method and a device for realizing lazy loading, electronic equipment and a storage medium. The lazy loading implementation method comprises the following steps: determining a lazy loading class defined as an abstract class to realize a lazy loading logic function, defining a target abstract method in the lazy loading class to realize target logic, and inheriting the lazy loading logic function by inheriting the lazy loading class by at least two target service classes; in the page implementation process, a target function provided by a system is rewritten so as to implement the logic function of the target function when the target function is called back; and transmitting the duplicated target function into the target abstract method so as to realize the realization of the same target logic in at least two target business classes. The embodiment of the invention realizes the lazy loading by the definition of the abstract class and the abstract method, avoids the limitation of the system version, and improves the applicable scene of realizing the lazy loading.
Description
Technical Field
The embodiment of the invention relates to the technical field of communication, in particular to a method and a device for realizing lazy loading, electronic equipment and a storage medium.
Background
Lazy loading can automatically acquire more data when a user rolls a page, newly acquired data cannot influence the display of original data, and resource consumption of a server side is reduced to the maximum extent.
The implementation of the lazy loading service logic in the conventional lazy loading scheme 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 entity class and the entity method are limited to a certain extent in inheritance, and then access of different loading services is influenced, so that lazy loading in the traditional scheme is only adaptive to the support version of Android, and the traditional scheme is not adaptive under Android X, namely the lazy loading implementation method in the traditional scheme has the limitation problem on the Android version, the application range is not wide, developers need to develop the Android services separately according to different Android versions, and development workload is increased.
Disclosure of Invention
The embodiment of the invention provides a method and a device for realizing lazy loading, electronic equipment and a storage medium, which are used for avoiding the limitation of the realization of lazy loading by a system version and improving the application scene of the realization of lazy loading.
In a first aspect, an embodiment of the present invention provides a method for implementing lazy loading, including:
Determining a lazy loading class defined as an abstract class to realize a lazy loading logic function, and defining a target abstract method in the lazy loading class to realize target logic, wherein at least two target service classes inherit the lazy loading logic function by inheriting the lazy loading class;
in the page implementation process, the logic function of the target function is implemented when the target function is called back through the target function provided by the duplicating system;
and transmitting the duplicated target function into the target abstract method so as to realize the realization of the same target logic in at least two target business classes.
In a second aspect, an embodiment of the present invention further provides a device for implementing lazy loading, where the device includes:
the abstract definition module is used for determining a lazy loading class defined as an abstract class so as to realize a lazy loading logic function, and defining a target abstract method in the lazy loading class so as to realize target logic, wherein at least two target service classes inherit the lazy loading logic function by inheriting the lazy loading class;
the function duplicating module is used for realizing the logic function of the target function when the target function is called back through the target function provided by the duplicating system in the page realizing process;
And the method transmitting module is used for transmitting the target abstract method through the duplicated target function so as to realize the realization of the same target logic in at least two target business classes.
In a third aspect, an embodiment of the present invention further provides an electronic device, including:
one or more processors;
a storage device to store one or more programs,
when executed by the one or more processors, cause the one or more processors to implement a lazy load implementation method as in any embodiment of the present invention.
In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements a lazy load implementation method according to any embodiment of the present invention.
The embodiment of the invention is based on the lazy loading class defined as the abstract class to realize the lazy loading logic function and define the target abstract method in the lazy loading class to realize the target logic, and at least two target service classes inherit the lazy loading logic function by inheriting the lazy loading class; in the page implementation process, a target function provided by a system is rewritten so as to implement the logic function of the target function when the target function is called back; and transmitting the target abstract method through the duplicated target function so as to realize the realization of the same target logic in at least two target business classes. The lazy loading is realized by the definition of the abstract class and the abstract method, the limitation of a system version is avoided, and the applicable scene of lazy loading is improved.
Drawings
Fig. 1 is a flowchart of a method for implementing lazy loading according to a first embodiment of the present invention;
fig. 2 is a flowchart of a method for implementing lazy loading according to a second embodiment of the present invention;
fig. 3 is a schematic structural diagram of a lazy load implementation apparatus in the third embodiment of the present invention;
fig. 4 is a schematic structural diagram of an electronic device in a fourth embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
Example one
Fig. 1 is a flowchart of a lazy loading implementation method in the first embodiment of the present invention, and this embodiment may be applied to a case where lazy loading is implemented in an android version. The method can be executed by a lazy loading implementation apparatus, 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 shown in fig. 1, the method specifically includes:
The lazy loading refers to that when a page to be loaded has a lot of static resources (such as an online shopping page), in order to save user traffic and improve page performance, a user requests and loads the resources when browsing the current resources.
When a page is loaded, in order to implement a lazy load function, a lazy load class is generally defined first, and a logic function of lazy load is implemented in the lazy load class. In a traditional scheme, the definition of a lazy loading class for realizing a lazy loading logic function is usually an entity class, but the lazy loading function needs to be used in Android systems of different versions, the specific lazy loading details of different pages may not be the same, if the definition is the entity class, redefinition is needed in each page implementation class, and the applicability is low.
In the embodiment of the invention, the lazy loading class is defined as the abstract class, so that the constraint behavior of the implementation class of the concrete service is improved. And defining the lazy loading class as an abstract class for facilitating inheritance of the business classes, wherein each business class is used for loading different types of pages. Through the logic function of the lazy loading realized in the abstract class, the logic function of the lazy loading is dynamically inherited after the business class inherits the lazy loading class, the success of business access is reduced, the development efficiency is greatly improved, and the condition that developers need to develop a set of complete lazy loading logic for each business class is avoided. Illustratively, the definition of a particular class of lazy load classes is as follows: abstrat class lazyFragmentAndriodx: fragment (). Wherein abstrat represents that the class is defined as an abstract class, LazyFragmentAndrodidX represents the name of a lazy loading class, and Fragment represents a function name in the lazy loading class.
Since there may be differences in each service in a part of the logic functions in the lazy loading logic function, in order to improve the applicable range of the part of the logic functions, a target abstraction method is defined for the part of the logic functions to implement the target logic. Therefore, when different target business classes inherit the lazy loading class, the target abstraction method can be described specifically according to own logic, and meanwhile, different target business classes inherit the logic function in the lazy loading class through inheriting the lazy loading class. The application range of the lazy loading class is widened.
In one possible embodiment, the target abstraction method includes a get page layout ID method, a view initialization method, and a lazy load initialization logic method; the method for obtaining the page layout ID is used for obtaining the layout ID information of the current page, the view initialization method is used for designing view initialization logic, and the lazy loading initialization logic method is used for designing lazy loading initialization service logic.
When the layout ID information of the current page is acquired, the logic in different types of page acquisition methods can be different; similarly, there will be differences between the view initialization logic and the lazy loaded initialization service logic in different types of pages, so that abstract methods are defined for these logics to perform respective service implementation for subsequent different service implementation classes.
Illustratively, the specific definition of the method for obtaining the page layout ID is as follows: abstration fun getLayoutId (), Int. The abstract method is named getLayoutId, and the return value is an Int type data, wherein the Int type data is the layout ID information of the current page. The specific function definition of the view initialization method is as follows: abstrat fun initView (View: View, savedlnstancestate: Bundle. The specific definition of the lazy load initialization logic method is as follows: abstract fun lazyInit (). Wherein abstrat represents that the method is defined as an abstract method, getLayoutId represents the name of a method for acquiring a page layout ID, initView represents the name of a view initialization method, and lazyInit represents the name of a lazy loading initialization logic method. For the initView method, two parameters are required to be input into the function, the type of the first parameter is the View type defined in the View class, and the second parameter is the Bundle type defined in the savedlnstancestate class. When the service class is defined concretely, the service class inherits the lazy loading class, and the target abstract method is defined concretely in the service class so as to realize the calling of the target abstract method, and the concrete realization of the target abstract method is realized by subclasses, namely methods corresponding to the same name in the inherited service class. Thereby realizing the same target logic function of different services.
102, in the process of realizing the page, the target function provided by the system is rewritten so as to realize the logic function of the target function when the target function is called back.
The page implementation process refers to a process from page loading to page destruction after page loading is completed. In the process of realizing the page, the page can call back the related objective function provided by the Android system, but because the implementation logic function in the related objective function is different from the actual requirement, the related objective function provided by the system is rewritten in the embodiment of the invention so as to realize the specific logic function when the page calls back the objective functions. Specifically, the target function of the page callback is determined according to the stage of the page implementation process.
And 103, transmitting the target abstract method through the duplicated target function to realize the realization of the same target logic in at least two target business classes.
Because the duplicated target function is used for realizing a concrete business logic method, a target abstraction method is introduced into the duplicated target function, and the introduced target abstraction method is determined according to the stage of the page realization process. The concrete realization of the target abstract method transmitted in the duplicated target function is realized through subclasses thereof, namely corresponding service inheritance classes, so that the same logic function called in different service classes is realized.
In one possible embodiment, the method further comprises: a globally dynamically acquired printing label identification variable is defined, and log information is conveniently printed when log output is carried out on a subsequent inherited service class. Illustratively, the specific print label identification variable TAG is defined as follows: private val TAG ═ this.
In the traditional scheme, the print label identifier is a character string, and in the embodiment of the invention, the print label identifier is a dynamically acquired variable, wherein private indicates that the print label identifier variable is of a private type and is only called by members in a lazy loading class, val indicates the data type of the print label identifier variable, TAG indicates the name of the print label identifier variable, this is the current class, javaClass is an object created in the current class, and simplename is a variable in the object. Because this represents the current object and represents the object of the inherited service class for different inherited service classes, the class name of the current class is output when the subsequent inherited class accesses the TAG, and the efficiency and performance of log output can be greatly improved when the log is printed and debugged.
The embodiment of the invention is based on a lazy loading class defined as an abstract class to realize a lazy loading logic function and define a target abstract method in the lazy loading class to realize target logic, and at least two target service classes inherit the lazy loading logic function by inheriting the lazy loading class; in the page implementation process, the logic function of the target function is implemented when the target function is called back through the target function provided by the duplicating system; and transmitting the duplicated target function into the target abstract method so as to realize the realization of the same target logic in at least two target business classes. The lazy loading implementation is realized by the definition of the abstract class and the abstract method, the limitation of a system version is avoided, and the applicable scene of the lazy loading implementation is improved.
Example two
Fig. 2 is a flowchart of a method for implementing lazy loading in the second embodiment of the present invention, and the second embodiment further optimizes based on the first embodiment. As shown in fig. 2, the method includes:
The page loading is an initial process in a page implementation process, when the page is lazy to load, the page loading is preferably carried out, an onCreateView function provided by a system can be called back when the page is loaded, and the function is a function provided by the system for loading the page. In the embodiment of the present invention, different page loading logics are different, and need to be determined according to the layout information of the current page, so the onCreateView function needs to be rewritten to realize a specific page layout loading logic.
Illustratively, first, an onCreateView function is called back when a page is loaded, so that a specific business logic method is implemented by copying the function, and the specific copying method is as follows: override fun onCreateView (infilter: LayoutInflater, container: ViewGroup? {}. The override indicates that the onCreateView function is a duplicate function, the input parameters of the duplicate function are a LayoutInflater defined in an inflater class, a ViewGroup type defined in a contiiner class, and a Bundle type defined in a savedInstancestate class, and the input of the onCreateView function is not limited in the embodiment of the present invention, and can be determined according to specific implementation logic and the definition of the function. The carbon copy example is only one specific page loading carbon copy method, and specific parameter introduction in the carbon copy function is not limited in the embodiment of the present invention.
Since the duplicating onCreateView function is used for determining the specific logic of page loading, a method for acquiring the page layout ID is introduced into the duplicating function so as to realize that the method for acquiring the page layout ID is loaded in the target business class and the layout ID information of the current page is returned, and the specific page loading is carried out according to the layout ID information of the current page.
Illustratively, on the basis of the above example, the loading of the page layout is implemented by calling an invalidate method in an ifilter object in the onCreateView function, and the specific function call is as follows: turn infllate (getLayoutId (), container, false). The function represents an inflate function in a calling inflater class, and the function has three incoming arguments, one is a layout ID returned by a target abstract method incoming get page layout ID method getlayout ID (), one is container, and the other is false.
A target abstract method is introduced to obtain the form of a page layout ID method getLayoutId () to load the page layout ID information returned by the target abstract method through an inflater.
And step 204, after the page is loaded, calling back the onViewCreated function to realize specific view initialization logic through the onViewCreated function provided by the carbon copy system when the page is loaded.
The page loading completion is a process after the page loading in the page implementation process, and when the page lazy loading is implemented, if the page needs view initialization, an onViewCreated function provided by the system is called back, wherein the onViewCreated function is provided by the system for view initialization of the page. In the embodiment of the present invention, different page view initialization logics are different, and determination needs to be performed according to the specific situation of the current page, so that the onViewCreated function needs to be rewritten to implement the specific page view initialization logic.
Illustratively, the system calls back the onViewCreated function when the page load is completed, so that the function is overwritten to implement a special initialization function for processing partial views in the function, and the method for overwriting onViewCreated of the system is as follows: override fun onViewCreated (View: View, savedInstancestate: Bundle. Wherein, override indicates that the onViewCreated function is a copy function, and the input of the copy function is a View variable defined in a View class and a Bundle type defined in a savedInstancestate class. The carbon copy example is only one specific view initialization method, and the specific parameter input in the carbon copy function is not limited in the embodiment of the present invention.
Since the carbon-on-ViewCreated function is used for determining the specific logic of page view initialization, a view initialization method is introduced into the carbon-on-View function so as to obtain the specific view initialization design logic in the view initialization method in the target business class.
Illustratively, on the basis of the above example, a specific view initialization logic function is implemented in the onViewCreated function by calling a view initialization method initView, and since the initView method is an abstract function, when calling the method, the system calls its implementation class, which is a service class that inherits the abstract class, that is, a view initialization method for a specific service, thereby implementing the target of the view initialization method with unified overall service.
And step 206, when the page is visible, calling back the onResume function to realize the loading visible logic of the page by copying the onResume function provided by the system.
The page visible stage occurs after initialization of the page view is completed in the page implementation process, and when page lazy loading is implemented, the page needs to be subjected to lazy loading initialization after the initialization of the page view is completed, that is, page visible is performed, and then an onResume function provided by the system can be called back, wherein the function is a function for performing visible processing on the page provided by the system. In the embodiment of the present invention, when performing visible processing on different pages, the lazy load initialization logic is different, and needs to be determined according to the specific situation of the current page, so that the onResume function needs to be rewritten to implement lazy load initialization when the specific page is visible, and perform page visibility.
Illustratively, the system will call back the onResume function after page view initialization is complete, so the logic that initiates lazy loading when the page is visible in the function is handled by overwriting the function. When a system page is to be visible, the onResume method is called back, and the method is rewritten to make a determination of lazy loading logic when the page is visible, wherein the specific rewriting method is as follows: override fun onResume () { }.
Since the carbon copy onResume function is used to make a page visible, a determination needs to be made in the function for the initialization logic of the lazy load. And introducing a lazy loading initialization logic method into the duplicating onResume function so as to obtain the specific lazy loading initialization design logic in the lazy loading initialization logic method in the target service class.
Illustratively, on the basis of the above example, the lazy load initialization logic determination function in the implementation class is triggered by calling a lazy load initialization logic method, i.e., a lazyInit () method, in the onResume function, so that the lazy load initialization logic of the service class is implemented.
In one possible embodiment, the method further comprises:
defining a global variable for marking whether a current page is loaded or not;
Correspondingly, in the copying onResume function, the method for introducing the lazy load initialization logic comprises the following steps:
in the copying onResume function, firstly, judging whether a current page is loaded or not through a global variable, and judging whether the current page is in a visible state or not through calling a visible state judging function of a system;
and if the current page is not loaded and is in an invisible state, transferring a lazy loading initialization logic method, and modifying a global variable to mark that the current page is loaded after the lazy loading initialization logic method is called.
In order to avoid performing secondary loading on a loaded page, a global variable is defined in the embodiment of the present invention to mark whether a current page is loaded. Illustratively, the global variables are specifically defined as follows: private var isLoaded ═ false, where initializing the global variable to false indicates that the initial state is unloaded.
Specifically, in the copying onResume function, if the current page is loaded, the lazy loading initialization logic determination process is not needed, and only when the current page is not loaded, the subsequent loading process is performed. Optionally, in addition to determining whether the current page is loaded through the global variable, a subsequent loading process may also be determined by determining whether the current page is in a visible state according to the determination provided by the system. If the current page is in a visible state, subsequent loading processes are not needed.
Illustratively, in duplicating the onResume function, first by determining the condition: if (! isLoaded &! isHidden) judges whether the current page has been loaded, and judges whether the current page is in a visible state by calling the isHidden method of the system, if the current page has not been loaded and belongs to an invisible state, a subsequent loading flow is executed, otherwise, no subsequent lazy loading initialization logic processing is performed.
If the judgment condition is met, the current page is considered to be loaded for the first time, and at the moment, the specific lazy loading initialization logic function in the implementation class can be triggered by calling the target abstract method lazyInit () method, so that the lazy loading initialization logic of the service class is realized.
After the lazy loading initialization logic method is called, the isLoaded variable is set to true by calling an isLoaded ═ true method, so that when the page is visible for the second time, the loaded page cannot be triggered to be loaded for the second time due to the fact that the judgment condition cannot be met, the problem that the page is repeatedly loaded is effectively solved, and page loading efficiency and page reuse rate are greatly improved.
And step 208, when the page view is destroyed, calling back the ontstroyView function to realize data cleaning operation through the ontstroyView function provided by the carbon copy system when the page view is destroyed.
In the carbon copy ontestroyView function, a global variable is modified to mark that the current page is not loaded.
And the destruction of the page view occurs after the initialization of lazy loading of the page view is completed in the page implementation process. When the page view is destroyed, an ondestryView function provided by the system is called back, and the function is a function for destroying the page provided by the system. In the embodiment of the invention, different data cleaning operations need to be performed when the method performs the pin on different pages, and the determination needs to be performed according to the specific situation of the current page, so that the ontstroyView function needs to be rewritten, and the ontstroyView function is called back to realize the data cleaning operation when the page view is destroyed.
Illustratively, when a view is destroyed, the system calls back the onDestroyView function, and the cleaning operation of data is realized by copying the function, and the specific copying method is as follows: override fun on DestroyView () { }. Wherein, override represents that the ontestroyview function is a duplicate function.
After the page is destroyed, the global variable for marking whether the current page is loaded needs to be modified, so that the global variable is set to be in an unloaded state after the page is destroyed, the problem that an empty view appears can be effectively indicated when the page view is loaded next time, the page implementation process can be further executed, the possible collapse problem after the view is destroyed is avoided, and the stability of the program is greatly improved. Illustratively, in the carbon copy ontestryView function, the value of the variable of isLoaded is reset to the value of the initialized state by calling the isLoaded ═ false method.
The embodiment of the invention is based on the lazy loading class defined as the abstract class to realize the lazy loading logic function and define the target abstract method in the lazy loading class to realize the target logic, and at least two target service classes inherit the lazy loading logic function by inheriting the lazy loading class; in the page implementation process, the logic function of the target function is implemented when the target function is called back through the target function provided by the duplicating system; and transmitting the target abstract method through the duplicated target function so as to realize the realization of the same target logic in at least two target business classes. The lazy loading is realized by the definition of the abstract class and the abstract method, the limitation of a system version is avoided, and the applicable scene of lazy loading is improved.
EXAMPLE III
Fig. 3 is a schematic structural diagram of a lazy loading implementation apparatus in the third embodiment of the present invention, which is applicable to the case of implementing lazy loading in the android version. As shown in fig. 3, the apparatus includes:
the abstract definition module 310 is configured to determine a lazy loading class defined as an abstract class to implement a lazy loading logic function, and define a target abstract method in the lazy loading class to implement a target logic, where at least two target service classes inherit the lazy loading logic function by inheriting the lazy loading class;
The function duplicating module 320 is configured to implement a logic function of the target function when the target function is called back by duplicating the target function provided by the system in the page implementation process;
a method importing module 330, configured to import the target abstract method through a duplicated target function to implement implementation of the same target logic in at least two target business classes.
The embodiment of the invention is based on a lazy loading class defined as an abstract class to realize a lazy loading logic function and define a target abstract method in the lazy loading class to realize target logic, and at least two target service classes inherit the lazy loading logic function by inheriting the lazy loading class; in the page implementation process, a target function provided by a system is rewritten so as to implement the logic function of the target function when the target function is called back; and transmitting the target abstract method through the duplicated target function so as to realize the realization of the same target logic in at least two target business classes. The lazy loading is realized by the definition of the abstract class and the abstract method, the limitation of a system version is avoided, and the applicable scene of lazy loading is improved.
Optionally, the target abstraction method includes a method of obtaining a page layout ID, a view initialization method, and a lazy load initialization logic method; the method for obtaining the page layout ID is used for obtaining the layout ID information of the current page, the view initialization method is used for designing view initialization logic, and the lazy loading initialization logic method is used for designing lazy loading initialization service logic.
Optionally, the function copying module includes a loading function copying unit, configured to:
when a page is loaded, the onCreateView function provided by the duplicating system is called back to realize a specific page layout loading logic;
correspondingly, the method incoming module comprises a loading method incoming unit for:
transmitting a method for acquiring a page layout ID into the duplicating onCreateView function so as to load the method for acquiring the page layout ID into a target business class and return the layout ID information of the current page; the specific implementation of the method for obtaining the page layout ID is realized through the inheritance functions of at least two target business classes so as to realize the implementation of the same target logic in at least two target business classes.
Optionally, the function copying module includes a view initialization function copying unit, configured to:
after the page is loaded, calling back the onViewCreated function to realize specific view initialization logic through the onViewCreated function provided by the carbon copy system when the page is loaded;
accordingly, the method import module includes a view initialization method import unit to:
transmitting a view initialization method into the copy onViewCreated function to realize the acquisition of a specific view initialization design logic in the view initialization method in a target business class; the specific implementation of the view initialization method is realized through inheritance functions in at least two target service classes, so as to realize the implementation of the same target logic in at least two target service classes.
Optionally, the function copying module includes a page loading function copying unit, configured to:
when the page is visible, the onResume function provided by the carbon copy system is called back to realize the loading visible logic of the page when the page is visible;
correspondingly, the method incoming module comprises a lazy load initialization method incoming unit for:
in the duplicating onResume function, a lazy loading initialization logic method is introduced to achieve the purpose of obtaining the specific lazy loading initialization design logic in the lazy loading initialization logic method in a target service class; the specific implementation of the lazy loading initialization logic method is realized through inheritance functions of at least two target service classes, so that the same target logic is realized in the at least two target service classes.
Optionally, the method further includes:
defining a global variable for marking whether a current page is loaded or not;
correspondingly, the lazy load initialization method transfer-in unit is specifically configured to:
in the copying onResume function, whether a current page is loaded or not is judged through the global variable, and whether the current page is in a visible state or not is judged by calling a visible state judging function of the system;
And if the current page is not loaded and is in an invisible state, transferring a lazy loading initialization logic method, and modifying the global variable to mark that the current page is loaded after the lazy loading initialization logic method is called.
Optionally, the function copying module includes a view destroying function copying unit, configured to:
when the page view is destroyed, calling back the ontstroyView function to realize data cleaning operation through the ontstroyView function provided by the carbon copy system when the page view is destroyed;
in the carbon copy ontestroyView function, the global variable is modified to mark that the current page is not loaded.
The lazy loading implementation device provided by the embodiment of the invention can execute the lazy loading implementation method provided by any embodiment of the invention, and has corresponding functional modules and beneficial effects for executing the lazy loading implementation method.
Example four
Fig. 4 is a schematic structural diagram of an electronic device according to a fourth embodiment of the present invention. FIG. 4 illustrates a block diagram of an exemplary electronic device 12 suitable for use in implementing embodiments of the present invention. The electronic device 12 shown in fig. 4 is only an example and should not bring any limitation to the function and the scope of use of the embodiment of the present invention.
As shown in FIG. 4, electronic device 12 is embodied in the form of a general purpose computing device. The components of electronic device 12 may include, but are not limited to: one or more processors or processing units 16, a system memory device 28, and a bus 18 that couples various system components including the system memory device 28 and the processing unit 16.
The system storage 28 may include computer system readable media in the form of volatile memory devices, such as Random Access Memory (RAM)30 and/or cache storage 32. The electronic device 12 may further include other removable/non-removable, volatile/nonvolatile computer system storage media. By way of example only, storage system 34 may be used to read from and write to non-removable, nonvolatile magnetic media (not shown in FIG. 4, and commonly referred to as a "hard drive"). Although not shown in FIG. 4, a magnetic disk drive for reading from and writing to a removable, nonvolatile magnetic disk (e.g., a "floppy disk") and an optical disk drive for reading from or writing to a removable, nonvolatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 18 by one or more data media interfaces. Storage 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 embodiments of the invention.
A program/utility 40 having a set (at least one) of program modules 42 may be stored, for example, in storage 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which examples or some combination thereof may comprise an implementation of a network environment. Program modules 42 generally carry out the functions and/or methodologies of embodiments of the invention as described.
The processing unit 16 executes various functional applications and data processing by running programs stored in the system storage device 28, for example, implementing a lazy load implementation method provided by the embodiment of the present invention, including:
determining a lazy loading class defined as an abstract class to realize a lazy loading logic function, defining a target abstract method in the lazy loading class to realize target logic, and inheriting the lazy loading logic function by inheriting the lazy loading class by at least two target service classes;
in the page implementation process, the logic function of the target function is implemented when the target function is called back through the target function provided by the duplicating system;
and transmitting the duplicated target function into the target abstract method so as to realize the realization of the same target logic in at least two target business classes.
EXAMPLE five
The fifth embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the lazy loading implementation method provided in the fifth embodiment of the present invention, and the method includes:
determining a lazy loading class defined as an abstract class to realize a lazy loading logic function, defining a target abstract method in the lazy loading class to realize target logic, and inheriting the lazy loading logic function by inheriting the lazy loading class by at least two target service classes;
In the page implementation process, a target function provided by a system is rewritten so as to implement the logic function of the target function when the target function is called back;
and transmitting the target abstract method through the duplicated target function so as to realize the realization of the same target logic in at least two target business classes.
Computer storage media for embodiments of the invention may employ any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + +, or the like, as well as conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the 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 the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. Those skilled in the art will appreciate that the present invention is not limited to the particular embodiments described herein, and that various obvious changes, rearrangements and substitutions will now be apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in some detail by the above embodiments, the invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the invention, and the scope of the invention is determined by the scope of the appended claims.
Claims (10)
1. A lazy loading implementation method is characterized by comprising the following steps:
determining a lazy loading class defined as an abstract class to realize a lazy loading logic function, defining a target abstract method in the lazy loading class to realize target logic, and inheriting the lazy loading logic function by inheriting the lazy loading class by at least two target service classes;
in the page implementation process, a target function provided by a system is rewritten so as to implement the logic function of the target function when the target function is called back;
and transmitting the duplicated target function into the target abstract method so as to realize the realization of the same target logic in at least two target business classes.
2. The method of claim 1, wherein the target abstraction method includes a get page layout ID method, a view initialization method, and a lazy load initialization logic method; the method for obtaining the page layout ID is used for obtaining the layout ID information of the current page, the view initialization method is used for designing view initialization logic, and the lazy loading initialization logic method is used for designing lazy loading initialization service logic.
3. The method of claim 2, wherein in the page implementation process, by copying an objective function provided by a system to implement a logical function of the objective function when the objective function is called back, the method comprises:
when a page is loaded, the onCreateView function provided by the copying system is called back to realize a specific page layout loading logic;
correspondingly, the target abstract method is introduced through the duplicated target function so as to realize the realization of the same target logic in at least two target business classes, and the method comprises the following steps:
transmitting a method for acquiring a page layout ID into the duplicating onCreateView function so as to load the method for acquiring the page layout ID into a target business class and return the layout ID information of the current page; the specific implementation of the method for obtaining the page layout ID is realized through the inheritance functions of at least two target business classes so as to realize the implementation of the same target logic in at least two target business classes.
4. The method of claim 2, wherein in the page implementation process, by copying an objective function provided by a system to implement a logical function of the objective function when the objective function is called back, the method comprises:
after the page is loaded, calling back the onViewCreated function to realize specific view initialization logic through the onViewCreated function provided by the carbon copy system when the page is loaded;
correspondingly, the target abstract method is introduced through the duplicated target function so as to realize the realization of the same target logic in at least two target business classes, and the method comprises the following steps:
transmitting a view initialization method in an onViewCreated function so as to obtain specific view initialization design logic in the view initialization method in a target business class; the specific implementation of the view initialization method is realized through inheritance functions in at least two target service classes, so as to realize the implementation of the same target logic in at least two target service classes.
5. The method of claim 2, wherein in the page implementation process, by copying an objective function provided by a system to implement a logical function of the objective function when the objective function is called back, the method comprises:
When the page is visible, calling back the onResume function to realize the loading visible logic of the page through the onResume function provided by the carbon copy system when the page is visible;
correspondingly, the target abstract method is introduced through the duplicated target function so as to realize the realization of the same target logic in at least two target business classes, and the method comprises the following steps:
in the copying onResume function, a lazy loading initialization logic method is introduced to obtain specific lazy loading initialization design logic in the lazy loading initialization logic method in a target service class; the specific implementation of the lazy loading initialization logic method is realized through inheritance functions of at least two target service classes, so that the same target logic is realized in the at least two target service classes.
6. The method of claim 5, further comprising:
defining a global variable for marking whether a current page is loaded or not;
accordingly, in duplicating the onResume function, an incoming lazy load initialization logic method includes:
in the copying onResume function, firstly, judging whether a current page is loaded or not through the global variable, and judging whether the current page is in a visible state or not through calling a visible state judging function of a system;
And if the current page is not loaded and is in an invisible state, transferring a lazy loading initialization logic method, and modifying the global variable to mark that the current page is loaded after the lazy loading initialization logic method is called.
7. The method of claim 6, wherein in the page implementation process, by copying an objective function provided by a system to implement a logical function of the objective function when the objective function is called back, the method comprises:
when the page view is destroyed, calling back the ontstroyView function to realize data cleaning operation through the ontstroyView function provided by the carbon copy system when the page view is destroyed;
in the carbon copy ontestroyView function, the global variable is modified to mark that the current page is not loaded.
8. A lazy load implementation apparatus, comprising:
the abstract definition module is used for determining a lazy loading class defined as an abstract class so as to realize a lazy loading logic function, and defining a target abstract method in the lazy loading class so as to realize target logic, wherein at least two target service classes inherit the lazy loading logic function by inheriting the lazy loading class;
the function duplicating module is used for realizing the logic function of the target function when the target function is called back through the target function provided by the duplicating system in the page realizing process;
And the method transmitting module is used for transmitting the target abstract method through the duplicated target function so as to realize the realization of the same target logic in at least two target business classes.
9. An electronic device, comprising:
one or more processors;
a storage device to store one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the lazy load implementation method of any one of claims 1-7.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the lazy load implementation method according to any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110041366.3A CN114764484A (en) | 2021-01-13 | 2021-01-13 | Lazy loading implementation method and device, electronic equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110041366.3A CN114764484A (en) | 2021-01-13 | 2021-01-13 | Lazy loading implementation method and device, electronic equipment and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN114764484A true CN114764484A (en) | 2022-07-19 |
Family
ID=82362986
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202110041366.3A Pending CN114764484A (en) | 2021-01-13 | 2021-01-13 | Lazy loading implementation method and device, electronic equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114764484A (en) |
Citations (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6715147B1 (en) * | 1997-03-31 | 2004-03-30 | International Business Machines Corporation | Method and system for interfacing a plurality of applications conforming to a standard |
WO2011072970A1 (en) * | 2009-12-18 | 2011-06-23 | Syddansk Universitet | Method, computer program product, and system for non-blocking dynamic update of statically typed class-based object-oriented software |
US9152543B1 (en) * | 2014-06-28 | 2015-10-06 | Fujitsu Limited | Symbolic execution with automatic abstractions |
CN107145354A (en) * | 2017-05-04 | 2017-09-08 | 武汉斗鱼网络科技有限公司 | Software frame and its construction method, electric terminal and readable storage medium storing program for executing |
CN107203555A (en) * | 2016-03-17 | 2017-09-26 | 阿里巴巴集团控股有限公司 | Page loading processing method and device |
CN107391119A (en) * | 2017-06-30 | 2017-11-24 | 武汉斗鱼网络科技有限公司 | A kind of horizontal/vertical screen implementation method and device |
WO2019091341A1 (en) * | 2017-11-08 | 2019-05-16 | 阿里巴巴集团控股有限公司 | Snapshot creation method, apparatus, and system |
CN111414152A (en) * | 2020-03-25 | 2020-07-14 | 北京字节跳动网络技术有限公司 | Method, system, readable medium and electronic device for implementing business logic |
CN112182456A (en) * | 2020-10-09 | 2021-01-05 | 厦门海晟融创信息技术有限公司 | Method and device for adapting various map clients based on JavaScript |
-
2021
- 2021-01-13 CN CN202110041366.3A patent/CN114764484A/en active Pending
Patent Citations (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6715147B1 (en) * | 1997-03-31 | 2004-03-30 | International Business Machines Corporation | Method and system for interfacing a plurality of applications conforming to a standard |
WO2011072970A1 (en) * | 2009-12-18 | 2011-06-23 | Syddansk Universitet | Method, computer program product, and system for non-blocking dynamic update of statically typed class-based object-oriented software |
US9152543B1 (en) * | 2014-06-28 | 2015-10-06 | Fujitsu Limited | Symbolic execution with automatic abstractions |
CN107203555A (en) * | 2016-03-17 | 2017-09-26 | 阿里巴巴集团控股有限公司 | Page loading processing method and device |
CN107145354A (en) * | 2017-05-04 | 2017-09-08 | 武汉斗鱼网络科技有限公司 | Software frame and its construction method, electric terminal and readable storage medium storing program for executing |
CN107391119A (en) * | 2017-06-30 | 2017-11-24 | 武汉斗鱼网络科技有限公司 | A kind of horizontal/vertical screen implementation method and device |
WO2019091341A1 (en) * | 2017-11-08 | 2019-05-16 | 阿里巴巴集团控股有限公司 | Snapshot creation method, apparatus, and system |
CN111414152A (en) * | 2020-03-25 | 2020-07-14 | 北京字节跳动网络技术有限公司 | Method, system, readable medium and electronic device for implementing business logic |
CN112182456A (en) * | 2020-10-09 | 2021-01-05 | 厦门海晟融创信息技术有限公司 | Method and device for adapting various map clients based on JavaScript |
Non-Patent Citations (4)
Title |
---|
ANDYJENNIFER: "Androidx 下 Fragment 懒加载的新实现", pages 2 - 5, Retrieved from the Internet <URL:https://www.jianshu.com/p/2201a107d5b5> * |
砸漏: "androidx下的fragment的lazy懒加载问题详解", pages 2, Retrieved from the Internet <URL:https://cloud.tencent.com/developer/article/1723878> * |
肖秋红: "Android动态加载框架EasyDynamicLoad的设计与实现", 《中国硕士学位论文库》, no. 2, 15 February 2019 (2019-02-15) * |
霂棪: "懒加载BaseLazyFragment原理及代码", Retrieved from the Internet <URL:https://zhuanlan.zhihu.com/p/267348549> * |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US9934005B2 (en) | Dynamically building locale objects or subsections of locale objects based on historical data | |
US6463565B1 (en) | Method for designing object-oriented table driven state machines | |
US8661426B2 (en) | Method frame aggregation for latest user-defined class loader identification | |
US20150169319A1 (en) | Verification of backward compatibility of software components | |
US9317258B2 (en) | Dynamic validation of models using constraint targets | |
US8806474B2 (en) | Computer-hardware, life-extension apparatus and method | |
US8688946B2 (en) | Selecting an auxiliary storage medium for writing data of real storage pages | |
US11281469B2 (en) | Saving and restoring machine state between multiple executions of an instruction | |
CN112970000A (en) | Ordering and merging instructions for general purpose processors | |
US20090077536A1 (en) | Programming environment with support for handle and non-handle user-created classes | |
US7707593B2 (en) | Object models enabling hosting content in a plurality of environments | |
US10831502B2 (en) | Migration of partially completed instructions | |
CN114764484A (en) | Lazy loading implementation method and device, electronic equipment and storage medium | |
CN112764729B (en) | Application software development method, device, computer equipment and readable storage medium | |
CN108628620A (en) | Implementation method, device, computer equipment and the storage medium of POS application and developments | |
CN109634636B (en) | Application processing method, device, equipment and medium | |
CN114035864A (en) | Interface processing method, interface processing device, electronic device, and storage medium | |
CN114185516A (en) | Method, device, equipment and medium for adapting list item view in Android system | |
CN113778388A (en) | Program development method and device | |
CN110673834A (en) | Source code calling method and device, computer equipment and storage medium | |
US7694301B1 (en) | Method and system for supporting input/output for a virtual machine | |
US9058339B2 (en) | Source control inheritance locking | |
CN113688358B (en) | System security detection method and device, electronic equipment, medium and product | |
CN114968209A (en) | Page management method, system, electronic equipment and storage medium | |
CN115756657A (en) | Intelligent contract loader implementation method based on JAVA and intelligent contract loader |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |