A method, apparatus, and storage medium for creating a view component
By directly using predefined instance creation methods when creating view components, the reflection process is avoided, and the problem of inefficient creation of view components in the existing technology is solved, which significantly improves the creation efficiency.
Patent Information
- Application Number
- CN202010613257.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-30
- Publication Date
- 2025-06-27
- Estimated Expiration
- 2040-06-30
AI Technical Summary
The prior art requires a reflection process when creating view components, resulting in waste of resources and poor efficiency.
When receiving interface rendering instructions, the target XML layout file is obtained, the class name of its target view component is parsed, and the instance creation method corresponding to the target class name is determined in the predefined instance creation method, and the instance is created directly without reflection.
Save time in view component creation and greatly improve the efficiency of view component creation.
Smart Images

Figure CN111782212B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of information technology, and particularly relates to a method, apparatus, and storage medium for creating view components. Background Art
[0002] With the continuous development of information technology, users can use application programs to browse a large amount of data, such as text data, image data, audio data, and card information, etc. Extensible Markup Language (XML) is the most commonly used tool for data transmission between various application programs, providing a format for describing structured data and simplifying data exchange and representation in the network.
[0003] In the related art, when an application program first renders and generates a view component, it first needs to parse the XML layout file to obtain the class name of each view component, and then perform reflection through the class name of the view component to create the corresponding instance and return it. Since the process of creating through reflection consumes a lot of device resources, the efficiency of creating view components is relatively poor. Summary of the Invention
[0004] Embodiments of this application provide a method, apparatus, and storage medium for creating view components, which can improve the efficiency of creating view components.
[0005] To solve the above technical problems, the embodiments of this application provide the following technical solutions:
[0006] A method for creating a view component, which is applied to an Android client. The creating method includes:
[0007] When receiving an interface rendering instruction, obtain a target Extensible Markup Language layout file;
[0008] Parse the target Extensible Markup Language layout file to obtain the target class name of the target view component for interface layout;
[0009] In a pre-defined instance creation method, determine the target instance creation method corresponding to the target class name, where the instance creation method is not a method of creating an instance through a reflection process;
[0010] Use the target instance creation method to create an instance corresponding to the target class name, and the instance is used to represent the target view component.
[0011] Correspondingly, the embodiments of this application also provide a device for creating a view component, including:
[0012] An obtaining unit, when receiving an interface rendering instruction, obtains a target Extensible Markup Language layout file;
[0013] A parsing unit, configured to parse the target Extensible Markup Language layout file to obtain a target class name of a target view component for interface layout;
[0014] A determining unit, configured to determine, in a pre-defined instance creation method, a target instance creation method corresponding to the target class name, where the instance creation method is not a method of creating an instance through a reflection process;
[0015] A creating unit, configured to use the target instance creation method to create an instance corresponding to the target class name, where the instance is used to represent the target view component.
[0016] Correspondingly, an embodiment of the present application further provides a storage medium, on which a computer program is stored. When the computer program runs on a computer, the computer is caused to execute the view component creation method provided in any embodiment of the present application.
[0017] In an embodiment of the present application, when an interface rendering instruction is received, a target Extensible Markup Language layout file is obtained; the target Extensible Markup Language layout file is parsed to obtain a target class name of a target view component for interface layout; in a pre-defined instance creation method, a target instance creation method corresponding to the target class name is determined; and the target instance creation method is used to create an instance corresponding to the target class name. In this way, by determining the target class name of the target view component for interface layout in the target Extensible Markup Language layout file, determining the target instance creation method corresponding to the target class name in a pre-defined instance creation method, and using the target instance creation method to create an instance corresponding to the target class name, subsequent reflection processing is not required, saving the time for creating the view component and greatly improving the efficiency of creating the view component. Description of the Drawings
[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for description in the embodiments will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative efforts.
[0019] Figure 1 is a schematic flowchart of the view component creation method provided in an embodiment of the present application;
[0020] Figure 2 is a schematic scenario diagram of the view component creation method provided in an embodiment of the present application;
[0021] Figure 3 is another schematic flowchart of the view component creation method provided in an embodiment of the present application;
[0022] Figure 4 It is another schematic diagram of the scene of the method for creating a view component provided by an embodiment of the present application;
[0023] Figure 5 It is a schematic structural diagram of a device for creating a view component provided by an embodiment of the present application;
[0024] Figure 6 It is another schematic structural diagram of a device for creating a view component provided by an embodiment of the present application;
[0025] Figure 7 It is a schematic structural diagram of a terminal provided by an embodiment of the present application. Detailed implementation manners
[0026] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative efforts shall fall within the protection scope of the present application.
[0027] The following will be described in detail respectively. It should be noted that the serial numbers of the following embodiments are not intended to limit the preferred order of the embodiments.
[0028] Embodiment 1
[0029] In this embodiment, a description will be made from the perspective of a device for creating a view component. The device for creating a view component may be specifically integrated in a network device with a storage unit and installed with a microprocessor and having computing capabilities. The network device may be a terminal or a server. The following will take a terminal as an example for description.
[0030] Please refer to Figure 1 , Figure 1 It is a schematic flowchart of the method for creating a view component provided by an embodiment of the present application. The method for creating a view component includes:
[0031] In step 101, when an interface rendering instruction is received, a target extensible markup language layout file is obtained.
[0032] Among them, the XML layout file is a file scheme for creating user interface (UI) elements of view components in an operating system, which is implemented by writing in XML. Thus, when the embodiment of this application receives an interface rendering instruction, such as generating a shopping interface of an application, etc., it obtains the XML layout file. Designing the user interface in the XML layout file can better isolate the appearance of the application from the code that controls the behavior of the application, so that each time the interface layout is modified or adjusted, only the code of the XML layout file needs to be modified instead of modifying the source code and recompiling.
[0033] In step 102, parse the target XML layout file to obtain the target class name of the target view component for interface layout.
[0034] Among them, all XML layout files in an application can be scanned through an automated script to obtain the corresponding target class names of all view components in the application. The view component is a display component in the user interface that composes the application, such as a text view component (TextView), an image view component (ImageView), etc.
[0035] In step 103, determine the target instance creation method corresponding to the target class name among the pre-defined instance creation methods.
[0036] It should be noted that, for better illustration of the embodiment of this application, please refer to Figure 2 for reference. When creating a view component (CreatView), that is, when the operating system wants to create a view component on the page, it needs to read and parse the XML layout file, obtain the class name of the view component, and call back the class name of the view component to the factory2 interface. When the factory2 interface is set in the operating system and new instances can be normally created and returned through this factory2 interface, then the operating system can directly use it. However, when the factory2 interface is not set, the operating system will continue to find the hash table of sConstruterMap to check if there is a constructor corresponding to the class name of the view component. If there is a constructor, it will use this constructor to create an instance and return the instance. However, when no constructor is found, the operating system will finally perform reflection through the class loader (classloader) to create and return an instance according to the view component. When creating a view component for the first time, there is no corresponding cached data, so it will definitely perform reflection through the class loader. Since the process of creating through reflection wastes a lot of resources of the operating system, the time for creating through reflection is very long, resulting in poor efficiency in creating view components. The method of the embodiment of this application can solve the above problems, and the specific steps are as follows:
[0037] Among them, the reason for reflecting on the view component through the class loader is that there is no corresponding cache for this view component in the operating system, that is, there is no instance creation method corresponding to the target class name. Therefore, the instance creation method of the target class name of the view component can be predefined, so that the predefined instance creation method can be directly used later to determine the target instance creation method corresponding to the target class name, without the need to reflect through the class loader, avoiding the steps of reflection creation.
[0038] In some embodiments, the step of determining the target instance creation method corresponding to the target class name in the predefined instance creation method may include:
[0039] (1) Determine the target constructor corresponding to the target class name in the pre-cached constructors
[0040] Among them, a preset XML file can be created. This preset XML file is a new XML file. Write the previously obtained view component and the attribute data for generating the view component into this preset XML file. In one embodiment, the attribute data may be the necessary attribute codes for generating this view component, such as the width and height data of this view component. For the convenience of subsequent preloading and improving the loading speed, the attribute data may only be the width and height data for generating this view component.
[0041] Furthermore, a preset tool class can be used, such as the AsyncLayoutInflater tool. This AsyncLayoutInflater tool is a tool class provided by Google officially and is used to asynchronously create view components. Asynchronously create the view components and attribute data in this preset XML file, but do not perform rendering and display on the screen, thus not causing a burden on the operating system resources. And because only the necessary attribute data is created, it can better save the operating system resources, and at the same time realize preloading of the view components, so that the target class name of the view component can be directly cached. Subsequently, in the pre-cached constructors, the target constructor corresponding to the target class name can be directly determined, and there is no need to go through the reflection process to generate the target class name of the view component.
[0042] For example, the preset XML file can be created in the following way:
[0043] <Framelayout xmlns=“http: / / schemas.android.com / apk / res / android” android:layout_width=ldp “android:layout_height=“ldp”>
[0044] Write the previously obtained view component "TextView" into the preset XML file and perform asynchronous non-rendering creation to preload the view component.
[0045]
[0046] In some embodiments, the step of preloading the view component to obtain the preloaded view component may include:
[0047] (1.1) Inherit the interface of the factory method to obtain a preset factory class;
[0048] (1.2) Use an automated script to scan one or more Extensible Markup Language layout files to collect the class names of view components;
[0049] (1.3) According to the preset syntax rules, write the correspondence between the class name of the view component and the instance creation code for creating the view component into the preset factory class in a hard-coded manner to obtain a custom instance creation class;
[0050] (1.4) In the predefined instance creation class, determine the target instance creation code corresponding to the target class name, where the instance creation class includes one or more groups of correspondences between the class names of view components and instance creation codes obtained through hard coding
[0051] Among them, please refer to Figure 2 at the same time. The interface of the factory method is the interface of the factory2 method, which can be used for creating view components. In the embodiment of the present application, a preset factory class is newly created, and the preset factory class inherits the interface of the original factory method.
[0052] Furthermore, scan all Extensible Markup Language layout files through an automated script to obtain the class names of view components. According to the preset syntax rules, write the correspondence between the class names of view components and the instance creation codes for creating view components into the preset factory class in a hard-coded manner to obtain a custom instance creation class, so that the target instance creation code corresponding to the required target class name can be directly determined based on the predefined instance creation class in the future, without using a class loader for reflection, avoiding the steps of reflection creation. In one embodiment, the preset syntax rules may be in the form of switch case.
[0053] For example, the class name of the view component and the instance creation code can be written into the preset factory method according to the preset syntax rules in the following manner:
[0054]
[0055] In step 104, use the target instance creation method to create an instance corresponding to the target class name.
[0056] Among them, since the target instance creation method has been predefined, the target instance creation method can be directly used to create an instance corresponding to the target class name. This instance is used to represent the target view component and does not require reflection through a subsequent class loader, avoiding the steps of reflection creation. After the instance is created, the instantiated view component is rendered to obtain the corresponding application page.
[0057] In some embodiments, the step of using the target instance creation method to create an instance corresponding to the target class name may include: using the target constructor to create an instance corresponding to the target class name.
[0058] Among them, since the class names and attribute data of the view components in the preset XML file have been asynchronously created without rendering, the class names of the view components already exist in the cache. The target constructor can be directly used to create an instance corresponding to the target class name, ensuring that subsequent reflection creation is not required.
[0059] In some embodiments, using the target instance creation method to create an instance corresponding to the target class name may include: using the target instance creation code to create an instance corresponding to the target class name.
[0060] Among them, since a preset factory class has been obtained as described above, when the operating system needs to create an instance of the class name of the view component, a new instance and return the instance can be directly performed through the preset factory class, ensuring that subsequent reflection creation is not required.
[0061] As can be seen from the above, in the embodiment of the present application, when an interface rendering instruction is received, a target extensible markup language layout file is obtained; the target extensible markup language layout file is parsed to obtain the target class name of the target view component for interface layout; in the predefined instance creation method, the target instance creation method corresponding to the target class name is determined; the target instance creation method is used to create an instance corresponding to the target class name. In this way, by determining the target class name of the target view component for interface layout in the target extensible markup language layout file, determining the target instance creation method corresponding to the target class name in the predefined instance creation method, and using the target instance creation method to create an instance corresponding to the target class name, subsequent reflection processing is not required, saving the time for creating the view component and greatly improving the efficiency of creating the view component.
[0062] Embodiment 2
[0063] According to the method described in Embodiment 1, the following will be further described in detail with examples.
[0064] In this embodiment, it will be described by specifically integrating the creation device of the view component in the server.
[0065] Please refer to Figure 3 , Figure 3 , which is another schematic flowchart of the method for creating a view component provided by an embodiment of this application. The method process may include:
[0066] In step 201, when the terminal receives an interface rendering instruction, it obtains a target Extensible Markup Language layout file.
[0067] In step 202, the terminal parses the target Extensible Markup Language layout file to obtain the target class name of the target view component for interface layout.
[0068] In step 203, the terminal annotates the view components in the Extensible Markup Language layout file through an annotation tool.
[0069] It should be noted that, please also refer to Figure 2 , in the process of generating a view component from an XML layout file, it is necessary to read and parse the XML layout file, and this process is also time-consuming.
[0070] In order to further save the instantiation creation time in this application, the terminal can pre-annotate the Extensible Markup Language layout file that needs to be optimized through an annotation tool, such as APT (Annotation Process Tool).
[0071] In step 204, the terminal converts the annotated view components into code data through a code generation framework, generates a class file, stores the logical relationship between the class file and the class name of the view component, and generates a hash table.
[0072] Among them, the terminal can convert the layout information in XML into corresponding java code data (code data) through a code generation framework, such as the javapoet framework, and then generate a java file (i.e., a class file), store the logical relationship between the class file and the layout information (the class name of the view component), and then generate a hash table.
[0073] For example, please also refer to Figure 4 , the javapoet framework converts the layout information C in XML into corresponding java code data, and then generates a class file B, stores the logical relationship between the layout information C and the class file, and then generates a hash table A.
[0074] In step 205, the terminal determines the class file corresponding to the target class name in the pre-created hash table.
[0075] Among them, please also refer to Figure 4 , the terminal can parse the layout information C in the pre-created hash table A to determine the class file B corresponding to the target class name.
[0076] In step 206, the terminal executes the class file to obtain an instance corresponding to the target class name.
[0077] Among them, the terminal can directly execute the class file B through the java compiler, create an instance of the target class name of the view component, and perform rendering processing on the instantiated view component to generate a corresponding application page. By directly executing the class file B for instantiation, there is no need to perform reflection through a class loader, avoiding the steps of reflection creation.
[0078] In step 207, when the terminal detects an execution exception, a prompt message is generated based on the target code data of the execution exception and displayed.
[0079] Among them, in the embodiment of the present application, a disaster tolerance logic is introduced. During the development stage, when the terminal detects an execution exception, the target code data of the exception is obtained to generate a corresponding prompt message to throw an exception and give a prompt.
[0080] As can be seen from the above, in the embodiment of the present application, when a page rendering instruction is received, the target extensible markup language layout file is obtained; the target extensible markup language layout file is parsed to obtain the target class name of the target view component for page layout; among the pre-defined instance creation methods, the target instance creation method corresponding to the target class name is determined; the target instance creation method is used to create an instance corresponding to the target class name. In this way, by determining the target class name of the target view component for page layout in the target extensible markup language layout file, and using the pre-defined instance creation method to determine the target instance creation method corresponding to the target class name, and using the target instance creation method to create an instance corresponding to the target class name, there is no need to perform subsequent reflection processing, saving the time for creating the view component and greatly improving the efficiency of creating the view component.
[0081] Embodiment 3
[0082] To facilitate better implementation of the view component creation method provided in the embodiment of the present application, the embodiment of the present application also provides a device based on the above view component creation method. The meanings of the nouns are the same as those in the above view component creation method, and the specific implementation details can refer to the description in the method embodiment.
[0083] Please refer to Figure 5 , Figure 5 which is a schematic structural diagram of the view component creation device provided in the embodiment of the present application. The view component creation device may include an acquisition unit 301, a parsing unit 302, a determination unit 303, a creation unit 304, etc.
[0084] An obtaining unit 301, configured to obtain a target Extensible Markup Language layout file when receiving an interface rendering instruction.
[0085] A parsing unit 302, configured to parse the target Extensible Markup Language layout file to obtain a target class name of a target view component for interface layout.
[0086] A determining unit 303, configured to determine a target instance creation method corresponding to the target class name in a pre-defined instance creation method, where the instance creation method is not a method of creating an instance through a reflection process.
[0087] In some embodiments, the determining unit 303 is configured to: determine a target instance creation code corresponding to the target class name in a pre-defined instance creation class, where the instance creation class includes a corresponding relationship obtained by hard coding between class names of one or more groups of view components and instance creation codes.
[0088] In some embodiments, the determining unit 303 is further configured to: inherit an interface of a factory method to obtain a preset factory class; use an automation script to scan one or more Extensible Markup Language layout files to collect class names of view components; write, in a hard-coded manner, a corresponding relationship between the class names of the view components and instance creation codes for creating the view components into the preset factory class according to a preset syntax rule to obtain a custom instance creation class; determine a target instance creation code corresponding to the target class name in a pre-defined instance creation class, where the instance creation class includes a corresponding relationship obtained by hard coding between class names of one or more groups of view components and instance creation codes.
[0089] In some embodiments, the determining unit 303 is further configured to determine a target constructor corresponding to the target class name in a pre-cached constructor.
[0090] In some embodiments, the determining unit 303 is further configured to determine a class file corresponding to the target class name in a pre-created hash table; where a corresponding relationship between class names of view components and class files is recorded in the hash table, and the class file is used to create an instance of the view component.
[0091] In some embodiments, the determining unit 303 is further configured to annotate view components in the Extensible Markup Language layout file through an annotation tool; convert the annotated view components into code data through a code generation framework to generate a class file; store a logical relationship between the class file and the class name of the view component to generate a hash table; determine a class file corresponding to the target class name in a pre-created hash table; where a corresponding relationship between class names of view components and class files is recorded in the hash table, and the class file is used to create an instance of the view component.
[0092] A creation unit 304 is configured to create an instance corresponding to the target class name by using the target instance creation method, and the instance is used to represent the target view component.
[0093] In some embodiments, the creation unit 304 is configured to create an instance corresponding to the target class name by using the target instance creation code.
[0094] In some embodiments, the creation unit 304 is further configured to create an instance corresponding to the target class name by using the target constructor.
[0095] In some embodiments, the creation unit 304 is further configured to execute the class file to obtain an instance corresponding to the target class name.
[0096] In some embodiments, as Figure 6 shown, the creation device of the view component further includes:
[0097] A prompt unit 305 is configured to generate a prompt message according to the target code data of the execution exception and display the prompt message when an execution exception is detected.
[0098] For the specific implementation of each of the above units, reference may be made to the previous embodiments, which will not be elaborated herein.
[0099] As can be seen from the above, in the embodiment of the present application, when the acquisition unit 301 receives an interface rendering instruction, a target extensible markup language layout file is acquired; the parsing unit 302 parses the target extensible markup language layout file to obtain a target class name of a target view component for interface layout; the determination unit 303 determines a target instance creation method corresponding to the target class name in a predefined instance creation method; the creation unit 304 creates an instance corresponding to the target class name by using the target instance creation method. In this way, by determining the target class name of the target view component for interface layout in the target extensible markup language layout file, determining the target instance creation method corresponding to the target class name in a predefined instance creation method, and creating an instance corresponding to the target class name by using the target instance creation method, subsequent reflection processing is not required, saving the time for creating the view component and greatly improving the efficiency of creating the view component.
[0100] Embodiment 4
[0101] The embodiment of the present application further provides a terminal, as Figure 7 shown, which shows a schematic structural diagram of the terminal involved in the embodiment of the present application. Specifically:
[0102] The terminal may include a processor 401 with one or more processing cores, a memory 402 with one or more computer-readable storage media, a power supply 403, an input unit 404, and other components. Those skilled in the art can understand,Figure 7 The terminal structure shown does not constitute a limitation on the terminal, and may include more or fewer components than shown, or combine certain components, or have different component arrangements. Among them:
[0103] The processor 401 is the control center of the terminal, connecting various parts of the entire terminal using various interfaces and lines. By running or executing software programs and / or modules stored in the memory 402, and by calling the data stored in the memory 402, it executes various functions of the terminal and processes data, thereby performing overall detection of the terminal. Optionally, the processor 401 may include one or more processing cores; preferably, the processor 401 may integrate an application processor and a modem processor. Among them, the application processor mainly processes the operating system, user interface, application programs, etc., and the modem processor mainly processes wireless communication. It can be understood that the above-mentioned modem processor may not be integrated into the processor 401.
[0104] The memory 402 can be used to store software programs and modules. The processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 402. The memory 402 mainly includes a program storage area and a data storage area. Among them, the program storage area can store the operating system, application programs required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the terminal, etc. In addition, the memory 402 can include high-speed random access memory, and can also include non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other volatile solid-state storage devices. Correspondingly, the memory 402 can also include a memory controller to provide the processor 401 with access to the memory 402.
[0105] The terminal further includes a power supply 403 for supplying power to each component. Preferably, the power supply 403 can be logically connected to the processor 401 through a power management system, so as to implement functions such as management of charging, discharging, and power consumption management through the power management system. The power supply 403 can also include any components such as one or more DC or AC power supplies, a recharge system, a power failure detection circuit, a power converter or inverter, and a power status indicator.
[0106] The terminal may further include an input unit 404, which can be used to receive input digital or character information, and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.
[0107] Although not shown, the terminal may further include a display unit and the like, which will not be elaborated here. Specifically, in this embodiment, the processor 401 in the terminal will, according to the following instructions, load the executable files corresponding to the processes of one or more application programs into the memory 402, and the processor 401 will run the application programs stored in the memory 402 to implement various functions as follows:
[0108] When receiving an interface rendering instruction, obtain a target Extensible Markup Language layout file;
[0109] Parse the target Extensible Markup Language layout file to obtain the target class name of the target view component for interface layout;
[0110] In the pre-defined instance creation methods, determine the target instance creation method corresponding to the target class name, where the instance creation method is not the method of creating an instance through a reflection process;
[0111] Use the target instance creation method to create an instance corresponding to the target class name, and this instance is used to represent the target view component.
[0112] In the above embodiments, the descriptions of each embodiment have their own emphases. For the parts not elaborated in a certain embodiment, reference can be made to the detailed description of the view component creation method above, which will not be elaborated here.
[0113] As can be seen from the above, the terminal in the embodiment of the present application can, when receiving an interface rendering instruction, obtain a target Extensible Markup Language layout file; parse the target Extensible Markup Language layout file to obtain the target class name of the target view component for interface layout; in the pre-defined instance creation methods, determine the target instance creation method corresponding to the target class name; use the target instance creation method to create an instance corresponding to the target class name. In this way, by determining the target class name of the target view component for interface layout in the target Extensible Markup Language layout file, in the pre-defined instance creation method, determine the target instance creation method corresponding to the target class name, and use the target instance creation method to create an instance corresponding to the target class name, there is no need to go through subsequent reflection processing, saving the time for creating view components and greatly improving the efficiency of creating view components.
[0114] Embodiment Five
[0115] Those of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructions or by controlling relevant hardware through instructions. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.
[0116] To this end, an embodiment of the present application provides a storage medium storing multiple instructions that can be loaded by a processor to execute the steps in any of the view component creation methods provided by the embodiments of the present application. For example, the instructions can execute the following steps:
[0117] When receiving an interface rendering instruction, obtain a target extensible markup language layout file;
[0118] Parse the target extensible markup language layout file to obtain the target class name of the target view component for interface layout;
[0119] In the predefined instance creation methods, determine the target instance creation method corresponding to the target class name, where the instance creation method is not a method of creating an instance through a reflection process;
[0120] Use the target instance creation method to create an instance corresponding to the target class name, and the instance is used to represent the target view component.
[0121] For the specific implementation of each of the above operations, reference can be made to the previous embodiments, which will not be elaborated here.
[0122] Among them, the storage medium may include: read-only memory (ROM, Read Only Memory), random access memory (RAM, Random Access Memory), a magnetic disk or an optical disc, etc.
[0123] Since the instructions stored in the storage medium can execute the steps in any of the view component creation methods provided by the embodiments of the present application, the beneficial effects achievable by any of the view component creation methods provided by the embodiments of the present application can be realized. For details, reference can be made to the previous embodiments, which will not be elaborated here.
[0124] The above has introduced in detail a view component creation method, apparatus, and storage medium provided by the embodiments of the present application. Specific examples are used in this article to elaborate on the principle and implementation manner of the present application. The description of the above embodiments is only used to help understand the method and its core idea of the present application; at the same time, for those skilled in the art, according to the idea of the present application, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation to the present application.
Claims
1. A method for creating a view component, characterized in that, Applied to an Android client, the creation method includes: When receiving an interface rendering instruction, obtain a target Extensible Markup Language layout file; Parse the target Extensible Markup Language layout file to obtain the target class name of the target view component for interface layout; Among the pre-defined instance creation methods, determine the target instance creation method corresponding to the target class name, where the instance creation method is not a method of creating an instance through a reflection process; Among the pre-defined instance creation methods, determining the target instance creation method corresponding to the target class name includes: Among the pre-cached constructors, determine the target constructor corresponding to the target class name; Wherein, the target constructor is created by asynchronously and non-renderingly creating the target view component and attribute data in a preset XML file; the preset XML file is a new XML file, and the preset XML file writes the target view component and attribute data, and the attribute data is the attribute data for generating the target view component; Use the target instance creation method to create an instance corresponding to the target class name, and the instance is used to represent the target view component; The step of using the target instance creation method to create an instance corresponding to the target class name includes: Use the target constructor to create an instance corresponding to the target class name.
2. The creation method according to claim 1, wherein Among the pre-defined instance creation methods, the step of determining the target instance creation method corresponding to the target class name includes: Among the pre-defined instance creation classes, determine the target instance creation code corresponding to the target class name, where the instance creation class includes a corresponding relationship obtained by hard coding between the class names of one or more groups of view components and the instance creation code; The step of using the target instance creation method to create an instance corresponding to the target class name includes: Use the target instance creation code to create an instance corresponding to the target class name.
3. The creation method according to claim 2, characterized in that The definition steps of the instance creation class include: Inherit the interface of the factory method to obtain a preset factory class; Use an automated script to scan one or more Extensible Markup Language layout files to collect the class names of view components; According to the preset syntax rules, write the corresponding relationship between the class names of the view components and the instance creation code for creating the view components into the preset factory class in a hard-coded manner to obtain a custom instance creation class.
4. The creation method according to claim 1, characterized in that, Among the pre-defined instance creation methods, the step of determining the target instance creation method corresponding to the target class name includes: Among the pre-created hash tables, determine the class file corresponding to the target class name; where the hash table records the corresponding relationship between the class names of view components and the class files, and the class files are used to create instances of the view components; The step of using the target instance creation method to create an instance corresponding to the target class name includes: Execute the class file to obtain an instance corresponding to the target class name.
5. The creation method according to claim 4, wherein The creation method of the hash table includes: Annotate the view components in the Extensible Markup Language layout file through an annotation tool; Convert the annotated view components into code data through a code generation framework to generate class files; Store the logical relationship between the class file and the class name of the view component, and generate a hash table.
6. The creation method according to any one of claims 1-5, characterized in that The creation method further includes: When an execution exception is detected, generate a prompt message according to the target code data of the execution exception and display it.
7. An apparatus for creating a view component, characterized in that, It includes: An acquisition unit, configured to acquire a target extensible markup language layout file when receiving an interface rendering instruction; A parsing unit, configured to parse the target extensible markup language layout file to obtain the target class name of the target view component for interface layout; A determination unit, configured to determine the target instance creation method corresponding to the target class name in a predefined instance creation method, where the instance creation method is not a method of creating an instance through a reflection process; The step of determining the target instance creation method corresponding to the target class name in a predefined instance creation method includes: determining the target constructor corresponding to the target class name in a pre-cached constructor; Wherein, the target constructor is created by asynchronously non-rendering the target view component and attribute data in a preset XML file; the preset XML file is a new XML file, and the preset XML file writes the target view component and attribute data, and the attribute data is the attribute data for generating the target view component; A creation unit, configured to create an instance corresponding to the target class name by using the target instance creation method, where the instance is used to represent the target view component; the step of creating an instance corresponding to the target class name by using the target instance creation method includes: creating an instance corresponding to the target class name by using the target constructor.
8. The creating device of the view component according to claim 7, characterized in that, The determination unit is configured to: Determine the target instance creation code corresponding to the target class name in a predefined instance creation class, where the instance creation class includes a corresponding relationship obtained by hard coding between the class names of one or more groups of view components and the instance creation code; The creation unit is configured to: Create an instance corresponding to the target class name by using the target instance creation code.
9. A storage medium, on which a computer program is stored, characterized in that, When the computer program runs on a computer, cause the computer to execute the view component creation method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Page rendering method and apparatus, page processing method and apparatus
CN108664296A