Data processing method and device, equipment, storage medium and product
Patent Information
- Application Number
- CN202510473611.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-15
- Publication Date
- 2026-10-23
AI Technical Summary
然而,在主线程需要使用子线程的Inflate操作的结果数据时,若子线程仍未完成Inflate操作,依然会造成主线程卡顿,影响视图显示效率
[0020]本公开实施例提供的数据处理方案,通过子线程执行针对预设布局文件的第一布局加载操作,并将第一布局加载操作对应的已创建的视图数据存入预设缓存队列中,通过主线程尝试获取预设布局文件的完整加载结果,若获取失败,则通过主线程触发子线程中断执行第一布局加载操作,通过主线程基于预设缓存队列执行针对预设布局文件的第二布局加载操作,得到预设布局文件的完整加载结果,其中,完整加载结果中包括第一布局加载操作对应的已创建的视图数据。通过采用上述技术方案,可提高布局文件的加载效率,进而提升页面视图的显示效率,提升应用程序运行的流畅度。
Smart Images

Figure CN122963665A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and more particularly to data processing methods, apparatus, devices, storage media, and products. Background Technology
[0002] The inflate operation transforms layout resources defined in an Extensible Markup Language (XML) file into an actual hierarchy of view objects existing in memory. In other words, it converts an XML-described UI layout into a view that can be displayed on the screen; it can be understood as a layout loading operation. Through the inflate mechanism, complex user interface layouts can be defined in XML files, making UI layout design and maintenance more convenient, separating code from the UI, and improving code maintainability and scalability.
[0003] Inflate operations are typically performed on the main thread. However, if the UI layout is complex, performing inflate operations on the main thread may cause the main thread to lag, affecting the smoothness and responsiveness of the UI. For example, performing an inflate operation on an item layout containing multiple nested RecyclerViews may cause noticeable lag when the RecyclerView is scrolled quickly.
[0004] To alleviate main thread lag, a child thread inflate mechanism was introduced. However, if the child thread has not yet completed the inflate operation when the main thread needs to use the result data from the child thread's inflate operation, it will still cause the main thread to lag, affecting view display efficiency. Summary of the Invention
[0005] This disclosure provides data processing methods, apparatus, devices, storage media, and products that can optimize existing data processing solutions for loading layout files.
[0006] In a first aspect, embodiments of this disclosure provide a data processing method, including:
[0007] The first layout loading operation for the preset layout file is executed by a sub-thread, and the view data created corresponding to the first layout loading operation is stored in the preset cache queue.
[0008] The main thread attempts to obtain the complete loading result of the preset layout file. If the acquisition fails, the main thread triggers the child thread to interrupt the execution of the first layout loading operation.
[0009] The main thread performs a second layout loading operation on the preset layout file based on the preset cache queue to obtain the complete loading result of the preset layout file, wherein the complete loading result includes the view data created corresponding to the first layout loading operation.
[0010] Secondly, embodiments of this disclosure also provide a data processing apparatus, including:
[0011] The data storage module is used to execute the first layout loading operation for the preset layout file through a sub-thread, and store the view data created corresponding to the first layout loading operation into a preset cache queue;
[0012] The interruption triggering module is used to attempt to obtain the complete loading result of the preset layout file through the main thread. If the acquisition fails, the main thread will trigger the sub-thread to interrupt the execution of the first layout loading operation.
[0013] The loading module is used to perform a second layout loading operation on a preset layout file based on the preset cache queue through the main thread, so as to obtain a complete loading result of the preset layout file, wherein the complete loading result includes the view data created corresponding to the first layout loading operation.
[0014] Thirdly, embodiments of this disclosure also provide an electronic device, the electronic device comprising:
[0015] One or more processors;
[0016] Storage device for storing one or more programs.
[0017] When the one or more programs are executed by the one or more processors, the one or more processors implement the data processing method provided in the embodiments of this disclosure.
[0018] Fourthly, embodiments of this disclosure also provide a storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to perform the data processing method provided in embodiments of this disclosure.
[0019] Fifthly, embodiments of this disclosure also provide a computer program product, including a computer program that, when executed by a processor, implements the data processing method provided in embodiments of this disclosure.
[0020] The data processing scheme provided in this embodiment executes a first layout loading operation on a preset layout file through a sub-thread, and stores the view data created corresponding to the first layout loading operation into a preset cache queue. The main thread attempts to obtain the complete loading result of the preset layout file. If the acquisition fails, the main thread triggers the sub-thread to interrupt the execution of the first layout loading operation. The main thread then executes a second layout loading operation on the preset layout file based on the preset cache queue to obtain the complete loading result of the preset layout file. The complete loading result includes the view data created corresponding to the first layout loading operation. By adopting the above technical solution, the loading efficiency of the layout file can be improved, thereby improving the display efficiency of the page view and enhancing the smoothness of application operation. Attached Figure Description
[0021] The above and other features, advantages, and aspects of the embodiments of this disclosure will become more apparent from the accompanying drawings and the following detailed description. Throughout the drawings, the same or similar reference numerals denote the same or similar elements. It should be understood that the drawings are schematic, and the originals and elements are not necessarily drawn to scale.
[0022] Figure 1 This is a schematic flowchart of a data processing method provided in an embodiment of the present disclosure;
[0023] Figure 2 This is a schematic flowchart of another data processing method provided in an embodiment of the present disclosure;
[0024] Figure 3 This is a schematic diagram of the structure of a data processing apparatus provided in an embodiment of the present disclosure;
[0025] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Detailed Implementation
[0026] Embodiments of this disclosure will now be described in more detail with reference to the accompanying drawings. While some embodiments of this disclosure are shown in the drawings, it should be understood that this disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of this disclosure. It should be understood that the accompanying drawings and embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of protection of this disclosure.
[0027] It should be understood that the steps described in the method embodiments of this disclosure may be performed in different orders and / or in parallel. Furthermore, the method embodiments may include additional steps and / or omit the steps shown. The scope of this disclosure is not limited in this respect.
[0028] The term "comprising" and its variations as used herein are open-ended inclusions, meaning "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Definitions of other terms will be given in the description below.
[0029] It should be noted that the concepts of "first" and "second" mentioned in this disclosure are used only to distinguish different devices, modules or units, and are not used to limit the order of functions performed by these devices, modules or units or their interdependencies.
[0030] It should be noted that the terms "a" and "a plurality of" used in this disclosure are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise expressly indicated in the context, they should be understood as "one or more".
[0031] To facilitate understanding of the technical solutions of the embodiments of this disclosure, related technologies are described below. User interface layouts can be defined in the form of layout files. When a page needs to be displayed, the layout file can be loaded, converting the layout resources in the layout file into a view object hierarchy that actually exists in memory, and then the page is displayed. Taking the Android operating system as an example, the Inflate operation, also known as the inflation operation or fill operation, can convert layout resources defined in an XML file into a view object hierarchy that actually exists in memory. The Inflate operation is usually performed on the main thread. However, if the interface layout is complex, performing the Inflate operation on the main thread may cause the main thread to lag, affecting the smoothness and responsiveness of the interface. To solve the lag problem of the main thread Inflate operation, there is an asynchronous Inflate implementation method in related technologies. AsyncLayoutInflater is a utility class provided by the Android operating system for asynchronously loading layouts. It allows loading layout files in a child thread, that is, performing the Inflate operation through a child thread, thereby avoiding the time-consuming Inflate operation on the main thread.
[0032] However, while the introduction of the child thread inflate mechanism alleviates main thread lag to some extent, several scenarios still exist. First, if the child thread has already completed its layout loading operation when the main thread needs the loaded result, the main thread can directly obtain the result, which can be considered lag-free. Second, if the child thread has not completed its layout loading operation when the main thread needs the loaded result, the main thread needs to wait for the child thread to finish, causing some lag. Third, if the child thread has not completed its layout loading operation when the main thread needs the loaded result, the main thread does not wait for the child thread to finish and restarts its layout loading operation, making the lag even more severe. Fourth, if the child thread has not yet started its layout loading operation when the main thread needs the loaded result, the layout loading operation needs to be restarted in either the main thread or the child thread, resulting in significant lag for the main thread.
[0033] In this embodiment, the loading progress is saved in the form of a cache queue during the layout loading process of the child thread, that is, the created view data is saved, and the main thread continues to perform layout loading operations based on the view data created by the child thread. This can effectively alleviate the main thread lag problem caused by the second and third situations mentioned above.
[0034] Figure 1 This is a flowchart illustrating a data processing method provided in an embodiment of the present disclosure. This embodiment is applicable to data processing for layout loading. The method can be executed by a data processing device, which can be implemented in software and / or hardware. Optionally, it can be implemented by an electronic device, such as a mobile terminal like a mobile phone, smartwatch, tablet computer, or personal digital assistant, or a device like a personal computer (PC) or server.
[0035] like Figure 1 As shown, the method includes:
[0036] Step 101: Execute the first layout loading operation for the preset layout file through a sub-thread, and store the created view data corresponding to the first layout loading operation into the preset cache queue.
[0037] In this embodiment, the preset layout file can be a layout file of a preset page in a preset application, and the specific format is not limited. Taking the Android operating system as an example, it can be an XML file. The preset page can be any page of the preset application.
[0038] For example, this step can be triggered in scenarios such as the startup phase of a preset application, when a preset page is opened, or when a preset page is refreshed, which can improve page loading efficiency.
[0039] In this embodiment of the disclosure, the layout loading operation may be, for example, an inflate operation. To facilitate the distinction between layout loading operations performed by the child thread and the main thread, the layout loading operation performed by the child thread is denoted as the first layout loading operation, and the layout loading operation performed by the main thread is denoted as the second layout loading operation.
[0040] For example, a preset layout file typically includes file content corresponding to multiple views. Each file content may correspond to a line or a label in the preset layout file. The layout loading operation can parse each file content one by one. After parsing a certain file content, the current view to be created can be determined based on the parsing result, and then the corresponding view data (also called view objects) can be created. Each time view data is created, it can be stored in a preset cache queue. For child threads, during the execution of the first layout loading operation for the preset layout file, the view data created by the first layout loading operation can be stored in the preset cache queue. Specifically, the view data can be stored in the preset cache queue in the order of creation.
[0041] Step 102: Attempt to obtain the complete loading result of the preset layout file through the main thread. If the acquisition fails, the main thread will trigger the child thread to interrupt the execution of the first layout loading operation.
[0042] For example, the main thread can determine when the complete loading result of the preset layout file is needed based on the actual situation. When that time arrives, the main thread attempts to obtain the complete loading result of the preset layout file. The complete loading result can include view data corresponding to all views in the preset layout file; the specific format is not limited, but it is generally a tree-like hierarchical structure, which can be simply referred to as a view tree. If the child thread has completed the first layout loading operation on the preset layout file, the complete loading result can be obtained. The complete loading result can be stored in a preset cache. The main thread can search for the complete loading result of the preset layout file in the preset cache; if it is not found, the retrieval fails.
[0043] For example, if the main thread fails to obtain the complete loading result of the preset layout file, it can determine that the first layout loading operation of the child thread has not been completed. To speed up the layout loading, the main thread can trigger the child thread to interrupt the execution of the first layout loading operation, so that the main thread can continue loading based on the loading progress of the child thread. The specific way the main thread triggers the child thread to interrupt the execution of the first layout loading operation is not limited. For example, it can send an interruption message to the child thread, or modify the state of the flag used to indicate the interruption status so that the child thread can know that an interruption is needed by reading the flag status.
[0044] Step 103: The main thread performs a second layout loading operation on the preset layout file based on the preset cache queue to obtain the complete loading result of the preset layout file, wherein the complete loading result includes the view data created corresponding to the first layout loading operation.
[0045] For example, the preset cache queue can be stored in the preset cache by the child thread. During the second layout loading operation for the preset layout file, the main thread can retrieve the view data created corresponding to the first layout loading operation by reading the preset cache queue. For view data that has already been created by the child thread, the main thread does not need to recreate it, thereby speeding up the execution of the second layout loading operation and obtaining the complete loading result of the preset layout file more quickly. Optionally, after retrieving view data from the preset cache queue, the main thread can add the retrieved view data to the view tree corresponding to the main thread. After all the view data in the preset cache queue has been retrieved by the main thread, the main thread can continue to create the corresponding view data for the uncreated views and add the created view data to the view tree corresponding to the main thread, ultimately obtaining a complete view tree as the complete loading result. Because the main thread is the application's user interface (UI) thread, the system prioritizes the main thread's resource needs to ensure the smoothness and responsiveness of the user interface. When the main thread is executing tasks, the system prioritizes allocating processor time and other resources to the main thread. Therefore, having the main thread take over from the child thread to continue the subsequent layout loading operations can effectively improve layout loading efficiency compared to waiting for the child thread to complete the first layout loading operation.
[0046] The data processing method provided in this disclosure involves a sub-thread executing a first layout loading operation on a preset layout file and storing the created view data corresponding to the first layout loading operation in a preset cache queue. The main thread attempts to obtain the complete loading result of the preset layout file. If the attempt fails, the main thread triggers the sub-thread to interrupt the execution of the first layout loading operation. The main thread then executes a second layout loading operation on the preset layout file based on the preset cache queue to obtain the complete loading result of the preset layout file. The complete loading result includes the view data corresponding to the first layout loading operation. By adopting the above technical solution, when the main thread needs the complete loading result of the layout file but the sub-thread has not yet completed, the sub-thread can be interrupted, allowing the main thread to continue the layout loading operation based on the view data already created by the sub-thread. This reduces the main thread's waiting time, reduces lag, improves the loading efficiency of the layout file, and thus improves the display efficiency of the page view and the smoothness of the application operation.
[0047] In some embodiments, the execution of the first layout loading operation for the preset layout file via a sub-thread includes: parsing the current first file content in the preset layout file via a sub-thread, and determining the current first view to be created based on the parsing result, wherein the current first file content is the first file content in the preset layout file that has not yet been parsed by the sub-thread; reading the current state of a preset marker via a sub-thread, and if the current state is the first state, creating the view data of the current first view by calling a preset creation function, wherein the first state is used to indicate continuing the execution of the first layout loading operation. The step of triggering the sub-thread to interrupt the first layout loading operation via the main thread includes: setting the state of the preset marker to a second state via the main thread, wherein the second state is used to indicate interrupting the execution of the first layout loading operation; and interrupting the execution of the first layout loading operation if the sub-thread determines that the current state of the read preset marker is the second state. Therefore, the child thread determines whether it can continue to execute the first layout loading operation by reading the current state of the preset marker, reducing the interaction between the child thread and the main thread. Furthermore, by reading the preset marker on a per-view basis before constructing view data for each view, the loading progress at the view granularity can be saved, making the handover between the main thread and the child thread more precise.
[0048] Specifically, the preset flag can be an instance variable used to indicate whether the layout loading operation needs to be interrupted. The preset flag can have two states: a first state and a second state. The first state indicates that the layout loading operation should continue, and the second state indicates that the layout loading operation should be interrupted. The initial state of the preset flag can be the first state, and the state switching of the preset flag can be controlled by the main thread.
[0049] The sub-threads can parse the contents of the preset layout files sequentially. For easy distinction, the contents parsed by the sub-threads are designated as the first file content, the contents parsed by the main thread as the second file content, the view to be created determined by the sub-threads as the first view, and the view to be created determined by the main thread as the second view. The current first file content is the first file content in the preset layout files that has not yet been parsed by the sub-threads. Taking the first parsing as an example, the first file content is determined as the current first file content, and the view to be created based on the parsing result is the current first view. If the preset flag indicates the current state is the first state, then the view data for the current first view is created. After creation, the created view data is stored in a preset cache queue. The sub-thread continues parsing the next file content, and the second file content is determined as the current first file content, and so on, until the first layout loading operation is interrupted, and view data creation stops. The view data for the current first view can be created by calling a preset creation function, which can be a function called during the layout loading operation to create view data, such as the `doCreateView` function.
[0050] When the main thread determines that it needs to trigger the child thread to interrupt the first layout loading operation, it sets the state of the preset marker to the second state. Subsequently, after the child thread determines the current first view to be created, it reads the current state of the preset marker. If the current state is the second state, it interrupts the execution of the first layout loading operation.
[0051] In some embodiments, after reading the current state of the preset marker through a sub-thread, and interrupting the first layout loading operation if the current state is the second state, the method further includes: releasing the preset lock identifier corresponding to the preset layout file through the sub-thread; wherein, the step of executing the second layout loading operation for the preset layout file through the main thread based on the preset cache queue includes: after obtaining the preset lock identifier through the main thread, executing the second layout loading operation for the preset layout file based on the preset cache queue. Therefore, switching between the main thread and the sub-thread can be achieved by switching the lock identifier holder, reducing the interaction between the main thread and the sub-thread, and improving system stability.
[0052] For example, after the main thread sets the state of the preset flag to the second state, it can wait for the child thread to release the preset lock flag. During the waiting process, it can try to acquire the preset lock flag. If it is successfully acquired, it can perform the second layout loading operation for the preset layout file based on the preset cache queue.
[0053] Figure 2This is a flowchart illustrating another data processing method provided in an embodiment of the present disclosure. The embodiments of the present disclosure are optimized based on the various optional solutions in the above embodiments. Specifically, the method includes the following steps:
[0054] Step 201: Execute the first layout loading operation for the preset layout file through a sub-thread, and store the created view data corresponding to the first layout loading operation into the preset cache queue.
[0055] Optionally, in this embodiment, the first layout loading operation and the second layout loading operation are inflation operations. The inflation operation is based on calling a preset inflation function, and the format of the returned data of the preset inflation function is a view tree. Taking the Android operating system as an example, the inflation operation is an Inflate operation. The preset inflation function can be a function predefined in a preset custom class. The preset custom class can inherit from the target system class. The target system class can be a layout inflater class (LayoutInflater, the core code class in the system's inflation process). By inheriting the LayoutInflater class, a custom inflation process can be implemented, thereby optimizing the originally uninterruptible inflation process in the system. The inflation process is a recursive execution process, mainly including creating a view, creating the layout parameters (LayoutParams) corresponding to the view, and adding a view (addView). The created view data can include the data obtained after creating the view and creating the layout parameters. Adding a view can include adding the created view data to the parent container, such as adding the created view data as a new node in the view tree and establishing a connection between the new node and the node corresponding to the parent container of the created view data.
[0056] During view creation, the `createViewFromTag` function needs to be called. After calling `createViewFromTag`, the current state of the preset tag can be read; that is, the state of the preset tag is checked every time `createViewFromTag` is entered. For example, a child thread parses the current first file content in the preset layout file, determines the current first view to be created based on the parsing result, calls the `createViewFromTag` function, reads the current state of the preset tag, and if the current state is the first state, the view data of the current first view is created by calling the preset creation function (such as `doCreateView`), and the created view data is stored in the preset cache queue. The `createViewFromTag` function is executed frequently and takes a long time during the inflate process. Using `createViewFromTag` as the entry point for checking the preset tag can reduce the amount of code development work and reduce the probability of problems.
[0057] Optionally, a view tree corresponding to the sub-thread can be constructed based on the view data already created according to the first layout loading operation. This preserves the process of creating the view tree for the layout inflator class, so that data can be returned according to the data format of the view tree in the future, reducing code changes and ensuring the stability of the application.
[0058] Step 202: Try to obtain the complete loading result of the preset layout file through the main thread. If the acquisition fails, the main thread will trigger the child thread to interrupt the execution of the first layout loading operation.
[0059] For example, if the main thread cannot obtain the complete loading result, it sets the state of the preset tag to the second state. When the child thread determines the new first view to be created and calls the `createViewFromTag` function again, it will re-check the preset tag. At this point, the current state has changed to the second state, so the child thread interrupts the first layout loading operation. Optionally, the child thread can throw a preset exception. By catching this preset exception at the outermost level of the layout loading code block, the layout loading process can continue. After throwing a preset exception, the child thread can release the preset lock identifier corresponding to the preset layout file, allowing the main thread to successfully acquire the preset lock identifier and perform subsequent operations.
[0060] For example, if the acquisition is successful, it is determined that the main thread has completed the first layout loading operation, and the page is displayed based on the acquired complete loading result.
[0061] Specifically, after the main thread triggers the interruption of the first layout loading operation in the child thread, the child thread adds a preset cache queue to the root node of the view tree corresponding to the child thread, thus obtaining the return data after the interruption of the first layout loading operation. Therefore, the design of returning data in the view tree format for the layout inflator class is retained, reducing code modifications and ensuring application stability.
[0062] Step 203: The main thread parses the current second file content in the preset layout file and determines the current second view to be created based on the parsing result. The current second file content is the first file content in the preset layout file that has not been parsed by the main thread.
[0063] For example, after obtaining the preset lock identifier, the main thread starts parsing the preset layout file from the beginning. The current second file content is the first file content in the preset layout file that has not yet been parsed by the main thread. Taking the first parsing as an example, the first file content is determined to be the current second file content. The view to be created based on the parsing result is the current second view. After adding the view data corresponding to the current second view to the view tree corresponding to the main thread, the main thread continues to parse the next file content, and the second file content is determined to be the current second file content. This process continues until all the file content in the preset layout file has been parsed.
[0064] Step 204: Determine whether view data exists in the preset cache queue through the main thread. If yes, proceed to step 205; otherwise, proceed to step 206.
[0065] For example, when a child thread stores view data into a preset cache queue, it stores the data in the order it was created. This creation order corresponds to the parsing order of the file content. Since the child thread and the main thread parse the same preset layout file, the parsing order of the child thread is consistent with the parsing order of the main thread. If view data exists in the preset cache queue, it means that the current second view has corresponding view data in the preset cache queue.
[0066] Step 205: Retrieve the view data located at the head of the preset cache queue and add the retrieved view data to the view tree corresponding to the main thread, then execute step 207.
[0067] As mentioned earlier, the creation order of view data is consistent with the parsing order of file content, and the parsing order of child threads is consistent with the parsing order of main threads. Therefore, after each parsing, the main thread retrieves view data from the preset cache queue in order, and the view data at the head of the queue is the view data corresponding to the current second view.
[0068] For ease of explanation, let's take a preset layout file containing 5 views as an example, parsed in the order of view a, view b, view c, view d, and view e. Assume that during the construction of view c by the child thread, the preset flag is set to the second state by the main thread. After the child thread determines that view d is to be constructed, it reads the preset flag and knows that the first layout loading operation needs to be interrupted. At this time, the preset cache queue contains view data a' for view a, view data b' for view b, and view data c' for view c. View data for views d and e have not yet been constructed. After the main thread starts executing the second layout loading operation, it determines that the current second view is view a. It finds that view data exists in the preset cache queue, so it retrieves view data a' from the head of the queue and adds it to the view tree corresponding to the main thread. The preset cache queue still contains view data b' and view data c'. The main thread then re-determines that the current second view is view b, retrieves view data b' from the head of the queue, and adds it to the view tree corresponding to the main thread, and so on.
[0069] Step 206: Create the view data for the current second view and add the created view data to the view tree corresponding to the main thread. Then, proceed to step 207.
[0070] As in the example above, if the current second view is view d, the view data c' in the preset cache queue no longer exists after it is retrieved. Therefore, the main thread cannot obtain the view data corresponding to view d. The main thread can create the view data d' of view d by calling the preset creation function and add the created view data d' to the view tree corresponding to the main thread.
[0071] Step 207: Determine whether the file content in the preset layout file has been completely parsed. If yes, proceed to step 208; otherwise, return to step 203.
[0072] For example, if the content of the preset layout file is not fully parsed, the operation of parsing the current second file content in the preset layout file through the main thread and determining the relevant operations for the current second view to be created based on the parsing result is repeated until the content of the preset layout file is fully parsed. Specifically, the main thread parses the current second file content (re-determined) in the preset layout file and determines the current second view to be created based on the parsing result. The main thread checks whether view data exists in the preset cache queue. If it exists, the view data at the head of the preset cache queue is retrieved and added to the view tree corresponding to the main thread. If it does not exist, the view data for the current second view is created and added to the view tree corresponding to the main thread. The main thread then checks whether the content of the preset layout file is fully parsed. If it is, the repeated operation of parsing the current second file content in the preset layout file through the main thread and determining the relevant operations for the current second view to be created based on the parsing result can be stopped, and step 208 can be executed.
[0073] As in the example above, after the main thread adds the created view data d' to the view tree corresponding to the main thread, there is still unparsed file content. The process returns to step 203, determines that the new current second view is view e, creates view data e' for view e, and adds view data e' to the view tree corresponding to the main thread. After the file content in the preset layout file is parsed, step 208 can be executed. At this time, the latest view tree is the complete loading result of the preset layout file.
[0074] Step 208: Determine the latest view tree corresponding to the main thread as the complete loading result of the preset layout file.
[0075] The data processing method provided in this embodiment involves a sub-thread performing a first layout loading operation on a preset layout file and storing the created view data corresponding to the first layout loading operation in a preset cache queue. If the main thread needs the complete loading result of the layout file but the sub-thread has not yet completed, the sub-thread can be interrupted. After parsing the preset layout file at the view granularity, the main thread determines the current view and checks if view data exists in the preset cache queue. If it does, the creation of view data can be skipped, and the view data of the view already created by the sub-thread can be directly retrieved from the head of the preset cache queue. If no view data exists in the preset cache queue, the main thread constructs the corresponding view data itself. After the preset layout file is parsed, the view tree finally constructed by the main thread is used as the complete loading result for page display. By adopting the above technical solution, the efficiency of the main thread taking over from the sub-thread to continue loading the layout file can be further improved, main thread lag can be reduced, the display efficiency of the page view can be further improved, and the smoothness of application operation can be enhanced.
[0076] Figure 3 This is a schematic diagram of the structure of a data processing apparatus provided in an embodiment of the present disclosure, as shown below. Figure 3 As shown, the device includes:
[0077] The data storage module 301 is used to execute a first layout loading operation for a preset layout file through a sub-thread, and store the view data created corresponding to the first layout loading operation into a preset cache queue;
[0078] The interrupt triggering module 302 is used to attempt to obtain the complete loading result of the preset layout file through the main thread. If the acquisition fails, the main thread will trigger the sub-thread to interrupt the execution of the first layout loading operation.
[0079] The loading module 303 is used to perform a second layout loading operation on a preset layout file based on the preset cache queue through the main thread, so as to obtain a complete loading result of the preset layout file, wherein the complete loading result includes the view data created corresponding to the first layout loading operation.
[0080] The data processing apparatus provided in this embodiment can trigger a child thread interruption operation when the main thread needs to use the complete loading result of the layout file, but the child thread has not yet completed the loading. The main thread can then continue the layout loading operation based on the view data already created by the child thread, reducing the waiting time of the main thread, reducing lag, improving the loading efficiency of the layout file, thereby improving the display efficiency of the page view and the smoothness of the application operation.
[0081] Optionally, the step of executing the first layout loading operation for the preset layout file via a sub-thread includes: parsing the current first file content in the preset layout file via a sub-thread, and determining the current first view to be created based on the parsing result, wherein the current first file content is the first file content in the preset layout file that has not been parsed by the sub-thread; reading the current state of a preset marker via a sub-thread, and if the current state is the first state, creating the view data of the current first view, wherein the first state is used to indicate to continue executing the first layout loading operation;
[0082] The interrupt triggering module includes:
[0083] A state setting unit is used to set a preset marked state to a second state through the main thread, wherein the second state is used to indicate the interruption of the execution of the first layout loading operation;
[0084] An interrupt unit is used to interrupt the execution of the first layout loading operation if the current state of the preset marker read is determined by the sub-thread to be the second state.
[0085] Optionally, the device may also include:
[0086] The identifier release module is used to release the preset lock identifier corresponding to the preset layout file through a sub-thread after interrupting the execution of the first layout loading operation when the current state of the preset identifier read by the sub-thread is determined to be the second state.
[0087] The loading module is used to: after obtaining the preset lock identifier through the main thread, perform a second layout loading operation on the preset layout file based on the preset cache queue.
[0088] Optionally, the view data in the preset cache queue is stored in the order of creation;
[0089] The loading module includes:
[0090] The view determination unit is used to parse the current second file content in the preset layout file through the main thread, and determine the current second view to be created based on the parsing result, wherein the current second file content is the first file content in the preset layout file that has not been parsed by the main thread.
[0091] The view processing unit is used to determine whether view data exists in the preset cache queue through the main thread. If it exists, the view data located at the head of the preset cache queue is retrieved from the queue and added to the view tree corresponding to the main thread. If it does not exist, the view data of the current second view is created and added to the view tree corresponding to the main thread.
[0092] The parsing and judgment unit is used to determine whether the file content in the preset layout file has been completely parsed.
[0093] The repeat unit is used to repeatedly execute the operation of parsing the current second file content in the preset layout file through the main thread and determining the relevant operation of the current second view to be created based on the parsing result when the parsing judgment unit determines that the parsing is not complete, until the file content in the preset layout file is parsed.
[0094] The result determination unit is used to determine the latest view tree corresponding to the main thread as the complete loading result of the preset layout file when the judgment result of the parsing judgment unit is that the parsing is complete.
[0095] Optionally, the first layout loading operation and the second layout loading operation are inflation operations. The inflation operation is implemented by calling a preset inflation function, and the format of the returned data of the preset inflation function is a view tree.
[0096] Optionally, the device may also include:
[0097] The view tree building module is used to build the view tree corresponding to the sub-thread based on the view data already created corresponding to the first layout loading operation through the sub-thread.
[0098] The return data determination module is used to add the preset cache queue to the root node of the view tree corresponding to the sub-thread after the first layout loading operation is interrupted by the main thread, thereby obtaining the return data after the first layout loading operation is interrupted.
[0099] The data processing apparatus provided in this disclosure can execute the data processing method provided in any embodiment of this disclosure, and has the corresponding functional modules and beneficial effects for executing the method.
[0100] It is worth noting that the various units and modules included in the above-mentioned device are only divided according to functional logic, but are not limited to the above division, as long as the corresponding functions can be realized; in addition, the specific names of each functional unit are only for easy differentiation and are not used to limit the protection scope of the embodiments of this disclosure.
[0101] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Reference is made below. Figure 4 It illustrates an electronic device suitable for implementing embodiments of the present disclosure (e.g., Figure 4 The diagram below shows the structure of the terminal device (or server) 400. The terminal device in this embodiment may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), and in-vehicle terminals (e.g., in-vehicle navigation terminals), as well as fixed terminals such as digital TVs and desktop computers. Figure 4 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.
[0102] like Figure 4 As shown, electronic device 400 may include a processing unit (e.g., central processing unit, graphics processor, etc.) 401, which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 402 or a program loaded from storage device 408 into random access memory (RAM) 403. The RAM 403 also stores various programs and data required for the operation of electronic device 400. The processing unit 401, ROM 402, and RAM 403 are interconnected via bus 404. An edit / output (I / O) interface 405 is also connected to bus 404.
[0103] Typically, the following devices can be connected to I / O interface 405: input devices 406 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 407 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 408 including, for example, magnetic tapes, hard disks, etc.; and communication devices 409. Communication device 409 allows electronic device 400 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 4 An electronic device 400 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively.
[0104] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication device 409, or installed from storage device 408, or installed from ROM 402. When the computer program is executed by processing device 401, it performs the functions defined in the methods of embodiments of this disclosure.
[0105] The names of messages or information exchanged between multiple devices in the embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of such messages or information.
[0106] The electronic device provided in this embodiment and the data processing method provided in the above embodiments belong to the same inventive concept. Technical details not described in detail in this embodiment can be found in the above embodiments, and this embodiment has the same beneficial effects as the above embodiments.
[0107] This disclosure provides a computer storage medium storing a computer program that, when executed by a processor, implements the data processing method provided in the above embodiments.
[0108] This disclosure provides a computer program product, including a computer program that, when executed by a processor, implements the data processing method provided in the above embodiments.
[0109] It should be noted that the computer-readable medium described in this disclosure can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this disclosure, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in connection with an instruction execution system, apparatus, or device. In this disclosure, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.
[0110] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device.
[0111] The aforementioned computer-readable medium carries one or more programs. When the electronic device executes the aforementioned one or more programs, the electronic device causes the following: a first layout loading operation is performed on a preset layout file via a sub-thread, and the created view data corresponding to the first layout loading operation is stored in a preset cache queue; the main thread attempts to obtain the complete loading result of the preset layout file, and if the acquisition fails, the main thread triggers the sub-thread to interrupt the execution of the first layout loading operation; the main thread performs a second layout loading operation on the preset layout file based on the preset cache queue to obtain the complete loading result of the preset layout file, wherein the complete loading result includes the created view data corresponding to the first layout loading operation.
[0112] Computer program code for performing the operations of this disclosure can be written in one or more programming languages or a combination thereof, including but not limited to object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0113] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0114] The units described in the embodiments of this disclosure can be implemented in software or in hardware. The names of modules do not necessarily limit the module itself; for example, a data storage module can also be described as "a module that executes a first layout loading operation on a preset layout file via a sub-thread and stores the created view data corresponding to the first layout loading operation into a preset cache queue."
[0115] The functions described above in this document can be performed, at least in part, by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: Field Programmable Gate Arrays (FPGAs), Application-Specific Integrated Circuits (ASICs), Application Standard Products (ASSPs), System-on-Chip (SoCs), Complex Programmable Logic Devices (CPLDs), and so on.
[0116] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0117] According to one or more embodiments of this disclosure, a data processing method is provided, comprising:
[0118] The first layout loading operation for the preset layout file is executed by a sub-thread, and the view data created corresponding to the first layout loading operation is stored in the preset cache queue.
[0119] The main thread attempts to obtain the complete loading result of the preset layout file. If the acquisition fails, the main thread triggers the child thread to interrupt the execution of the first layout loading operation.
[0120] The main thread performs a second layout loading operation on the preset layout file based on the preset cache queue to obtain the complete loading result of the preset layout file, wherein the complete loading result includes the view data created corresponding to the first layout loading operation.
[0121] According to one or more embodiments of this disclosure, the execution of the first layout loading operation for the preset layout file via a sub-thread includes:
[0122] The current first file content in the preset layout file is parsed by a sub-thread, and the current first view to be created is determined based on the parsing result. The current first file content is the first file content in the preset layout file that has not been parsed by the sub-thread.
[0123] The current state of the preset marker is read by a sub-thread. If the current state is the first state, the view data of the current first view is created. The first state is used to indicate that the first layout loading operation should continue.
[0124] The step of triggering the child thread to interrupt the first layout loading operation through the main thread includes:
[0125] The main thread sets the state of the preset marker to a second state, whereby the second state is used to indicate the interruption of the execution of the first layout loading operation;
[0126] If the current state of the preset marker read is determined to be the second state by a sub-thread, the execution of the first layout loading operation is interrupted.
[0127] According to one or more embodiments of this disclosure, after interrupting the execution of the first layout loading operation when the current state of the preset marker read is determined to be the second state by a sub-thread, the method further includes:
[0128] Release the preset lock identifier corresponding to the preset layout file through a sub-thread;
[0129] The step of executing a second layout loading operation for a preset layout file via the main thread based on the preset cache queue includes:
[0130] After obtaining the preset lock identifier through the main thread, the second layout loading operation for the preset layout file is executed based on the preset cache queue.
[0131] According to one or more embodiments of this disclosure, the view data in the preset cache queue is stored in the order of creation;
[0132] The step of performing a second layout loading operation on a preset layout file based on the preset cache queue by the main thread to obtain the complete loading result of the preset layout file includes:
[0133] The main thread parses the current second file content in the preset layout file and determines the current second view to be created based on the parsing result. The current second file content is the first file content in the preset layout file that has not been parsed by the main thread.
[0134] The main thread determines whether view data exists in the preset cache queue. If it does, the view data at the head of the preset cache queue is retrieved and added to the view tree corresponding to the main thread. If it does not exist, the view data of the current second view is created and added to the view tree corresponding to the main thread.
[0135] Determine whether the file content in the preset layout file has been completely parsed;
[0136] If the parsing is not completed, the parsing of the current second file content in the preset layout file is repeated through the main thread, and the relevant operations for determining the current second view to be created are determined based on the parsing results, until the file content in the preset layout file is parsed.
[0137] Once parsing is complete, the latest view tree corresponding to the main thread is determined as the complete loading result of the preset layout file.
[0138] According to one or more embodiments of this disclosure, the first layout loading operation and the second layout loading operation are inflation operations, which are implemented by calling a preset inflation function, and the format of the returned data of the preset inflation function is a view tree.
[0139] According to one or more embodiments of this disclosure, it further includes:
[0140] The view tree corresponding to the sub-thread is constructed by the sub-thread based on the view data already created corresponding to the first layout loading operation;
[0141] The process further includes, after the main thread triggers the child thread to interrupt the first layout loading operation, the following:
[0142] The preset cache queue is added to the root node of the view tree corresponding to the sub-thread by the sub-thread to obtain the return data after the first layout loading operation is interrupted.
[0143] The above description is merely a preferred embodiment of this disclosure and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features disclosed in this disclosure that have similar functions.
[0144] Furthermore, while the operations are described in a specific order, this should not be construed as requiring these operations to be performed in the specific order shown or in a sequential order. In certain environments, multitasking and parallel processing may be advantageous. Similarly, while several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of this disclosure. Certain features described in the context of individual embodiments may also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment may also be implemented individually or in any suitable sub-combination in multiple embodiments.
[0145] Although the subject matter has been described using language specific to structural features and / or methodological logic, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Rather, the specific features and actions described above are merely illustrative examples of implementing the claims.
Claims
1. A data processing method, characterized in that, include: The first layout loading operation for the preset layout file is executed by a sub-thread, and the view data created corresponding to the first layout loading operation is stored in the preset cache queue. The main thread attempts to obtain the complete loading result of the preset layout file. If the acquisition fails, the main thread triggers the child thread to interrupt the execution of the first layout loading operation. The main thread performs a second layout loading operation on the preset layout file based on the preset cache queue to obtain the complete loading result of the preset layout file, wherein the complete loading result includes the view data created corresponding to the first layout loading operation.
2. The method according to claim 1, characterized in that, The first layout loading operation for the preset layout file is performed via a sub-thread, including: The current first file content in the preset layout file is parsed by a sub-thread, and the current first view to be created is determined based on the parsing result. The current first file content is the first file content in the preset layout file that has not been parsed by the sub-thread. The current state of the preset marker is read by a sub-thread. If the current state is the first state, the view data of the current first view is created. The first state is used to indicate that the first layout loading operation should continue. The step of triggering the child thread to interrupt the first layout loading operation through the main thread includes: The main thread sets the state of the preset marker to a second state, whereby the second state is used to indicate the interruption of the execution of the first layout loading operation; If the current state of the preset marker read is determined to be the second state by a sub-thread, the execution of the first layout loading operation is interrupted.
3. The method according to claim 2, characterized in that, After interrupting the first layout loading operation when the current state of the preset marker read by the sub-thread is determined to be the second state, the process further includes: Release the preset lock identifier corresponding to the preset layout file through a sub-thread; The step of executing a second layout loading operation for a preset layout file via the main thread based on the preset cache queue includes: After obtaining the preset lock identifier through the main thread, the second layout loading operation for the preset layout file is executed based on the preset cache queue.
4. The method according to claim 1, characterized in that, The view data in the preset cache queue is stored in the order of creation; The step of performing a second layout loading operation on a preset layout file based on the preset cache queue by the main thread to obtain the complete loading result of the preset layout file includes: The main thread parses the current second file content in the preset layout file and determines the current second view to be created based on the parsing result. The current second file content is the first file content in the preset layout file that has not been parsed by the main thread. The main thread determines whether view data exists in the preset cache queue. If it does, the view data at the head of the preset cache queue is retrieved and added to the view tree corresponding to the main thread. If it does not exist, the view data of the current second view is created and added to the view tree corresponding to the main thread. Determine whether the file content in the preset layout file has been completely parsed; If the parsing is not completed, the parsing of the current second file content in the preset layout file is repeated through the main thread, and the relevant operations for determining the current second view to be created are determined based on the parsing results. Once parsing is complete, the latest view tree corresponding to the main thread is determined as the complete loading result of the preset layout file.
5. The method according to any one of claims 1-4, characterized in that, The first layout loading operation and the second layout loading operation are inflation operations. The inflation operation is based on calling a preset inflation function. The format of the data returned by the preset inflation function is a view tree.
6. The method according to claim 5, characterized in that, Also includes: The view tree corresponding to the sub-thread is constructed by the sub-thread based on the view data already created corresponding to the first layout loading operation; The process further includes, after the main thread triggers the child thread to interrupt the first layout loading operation, the following: The preset cache queue is added to the root node of the view tree corresponding to the sub-thread by the sub-thread to obtain the return data after the first layout loading operation is interrupted.
7. A data processing apparatus, characterized in that, include: The data storage module is used to execute the first layout loading operation for the preset layout file through a sub-thread, and store the view data created corresponding to the first layout loading operation into a preset cache queue; The interruption triggering module is used to attempt to obtain the complete loading result of the preset layout file through the main thread. If the acquisition fails, the main thread will trigger the sub-thread to interrupt the execution of the first layout loading operation. The loading module is used to perform a second layout loading operation on a preset layout file based on the preset cache queue through the main thread, so as to obtain a complete loading result of the preset layout file, wherein the complete loading result includes the view data created corresponding to the first layout loading operation.
8. An electronic device, characterized in that, The electronic device includes: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the data processing method as described in any one of claims 1-6.
9. A storage medium containing computer-executable instructions, characterized in that, The computer-executable instructions, when executed by a computer processor, are used to perform the data processing method as described in any one of claims 1-6.
10. A computer program product, characterized in that, It includes a computer program that, when executed by a processor, implements the data processing method as described in any one of claims 1-6.