An accurate update method for Android list

By receiving new and old data in the Android system, performing rapid comparison and difference calculations, and combining custom data types, the problems of insufficient scalability of existing tools and waste of resources are solved, and accurate data updates and performance optimization are achieved.

CN112394970BActive Publication Date: 2024-12-31GUIYANG YUWAN SCI TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202011277150.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-11-16
Publication Date
2024-12-31
Estimated Expiration
2040-11-16

AI Technical Summary

Technical Problem

The existing Android system's difference calculation tools only support list data types and are not scalable. When the data does not change, it will also cause the entire list to be updated, resulting in performance and memory waste.

Method used

Provides an accurate update method for Android lists. By receiving new and old data from users, checking the memory address and running version of the data set, using a combination of fast comparison and differential calculation, it supports custom data types, and only performs differential calculations and if necessary View updated.

Benefits of technology

It realizes differential calculations in background threads, reduces resource consumption, supports data types other than lists, improves data scalability and update accuracy, and avoids unnecessary view updates and performance waste.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112394970B_ABST
    Figure CN112394970B_ABST
Patent Text Reader

Abstract

The present invention discloses an Android list accurate update method, comprising the following steps: step 1: the system receives old data from the user according to the business needs; step 2: the system receives new data provided by the user; step 3: the system increments the internal running version as the running version of the update; step 4: checking the memory addresses of the new and old data sets of the user; step 5: checking whether the new data set of the user is empty and the old data set is not empty; step 6: checking whether the new data set of the user is not empty and the old data set is empty; step 7: switching to the background thread, calling the difference calculation algorithm provided by the system to perform the difference calculation; step 8: after the difference calculation is completed, switching to the main thread, checking whether the current running version is consistent with the running version inside the system. The present invention provides a set of difference calculation and update execution functions, which can easily perform difference calculation in the background thread and perform accurate update operations on the view.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to an updating method, and in particular to an accurate updating method for an Android list. Background Art

[0002] Currently, the Android list uses a series of caching technologies. Therefore, when the list needs to be updated, it is impossible to accurately find the items that need to be updated. Often, all items have to be updated, resulting in a waste of resources and performance. At the same time, if an entry has too much content, even if you only want to refresh a part of the entry, you have to refresh the entire entry, resulting in a waste of resources and performance.

[0003] Currently, for accurate update technology, it is necessary to calculate the difference between the new and old data. Currently, the Android system provides a difference calculation tool that can calculate the difference items between the new and old data, and the difference between the difference items; it also provides a set of tools for difference calculation in the background thread. However, the difference calculation tools provided by the existing Android system have the following disadvantages:

[0004] 1) The tool only supports lists, not other data types, and is not extensible;

[0005] 2) The difference is calculated based on the items. In many cases, the data in the list does not change, but changes in other conditions will cause the view of the entire list to change. In order to handle this situation, unnecessary fields must be added to each item in the list, and when the external conditions change, the mapping of all items in the list to this external condition must be updated at the same time, resulting in a waste of performance and memory. Summary of the invention

[0006] In order to solve the deficiencies of the above technologies, the present invention provides an Android list accurate update method.

[0007] In order to solve the above technical problems, the technical solution adopted by the present invention is: an Android list accurate update method, comprising the following steps:

[0008] An Android list accurate update method includes the following steps:

[0009] Step 1: The system receives old data from users according to their business needs;

[0010] Step 2: The system receives new data provided by the user;

[0011] Step 3: The system increments the internal running version as the running version for this data update;

[0012] Step 4: Check the memory addresses of the user's new and old data sets;

[0013] Step 5: Check whether the user's new data set is empty and the old data set is not empty;

[0014] Step 6: Check whether the user's new data set is not empty and the old data set is empty;

[0015] Step 7: Switch to the background thread and call the difference calculation algorithm provided by the Android system to perform difference calculation;

[0016] Step 8: After the difference calculation is completed, switch to the main thread to check whether the current running version is consistent with the running version inside the system.

[0017] Furthermore, in step 1, the system receives old data from the user according to business needs, including: the system receives the custom data type inherited from UpdateData, and the system receives the comparison operation between the custom new and old data inherited from UpdateDataDiffItemCallback.

[0018] Furthermore, the checking process of step 4 is as follows: if the memory addresses of the new and old data sets are the same, it is considered that the user data has not changed and does not need to be updated, and the update operation is terminated.

[0019] Furthermore, the checking process of step five is: if it is established, it means that the user has cleared the data. At this time, a quick delete operation can be performed without performing a difference calculation. After the quick delete operation is completed, the view is updated to end the update operation.

[0020] Furthermore, the checking process of step six is: if it is established, it means that the user has only performed a data addition operation. At this time, a quick addition operation can be performed without performing a difference calculation. After the quick addition operation is completed, the view is updated to end the update operation.

[0021] Furthermore, the checking process of step eight is: if the current running version is inconsistent with the running version inside the system, it means that a data update operation has been performed during the calculation period, and the result of this difference calculation is discarded; if the current running version is consistent with the running version inside the system, it means that no data update operation has been performed during the calculation period, and the result of this difference calculation is the result that the user really needs, and the result of this difference calculation is used to perform a view update.

[0022] The present invention provides a set of difference calculation and update execution functions, which can easily perform difference calculation in the background thread and execute accurate update operations on the view; at the same time, the data it supports is abstracted so that users can customize the incoming data and support more types and more diverse data besides lists. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] Figure 1 It is the overall flow chart of the present invention.

[0024] Figure 2 This is a difference calculation flow chart of the present invention.

[0025] Figure 3 It is a class diagram of the difference calculation method of the present invention. DETAILED DESCRIPTION

[0026] The present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments.

[0027] like Figure 1 An Android list accurate update method shown includes the following steps:

[0028] Step 1: The system receives old data from the user according to business needs; the system receives the custom data type inherited from UpdateData, and the system receives the comparison operation between the new and old data inherited from UpdateDataDiffItemCallback;

[0029] UpdateData and UpdateDataDiffItemCallback are necessary parameters for system operation and are closely related to the user's business. Users need to provide them.

[0030] Figure 3 In the code, I stands for interface, which is an abstract type unique to the object-oriented programming language Java. It requires that all classes that implement it should have the member variables and methods it declares. Interfaces cannot be instantiated, but can only be implemented by ordinary classes to have the functions defined by the interface. The so-called instantiation refers to obtaining an object of the interface through the new instruction.

[0031] A stands for abstract class. Abstract class means abstract class, which is an abstract type unique to the object-oriented programming language Java. You can define ordinary member methods as well as abstract member methods in it.

[0032] The so-called abstract member method is a member method that does not have a specific implementation, so the abstract class cannot be instantiated. The abstract method of the abstract class can only be given specific implementation content by having other classes inherit the abstract class.

[0033] The difference between an abstract class A and an interface I is that an abstract class is a class. In Java, a class can only inherit from one class, but it can implement multiple interfaces.

[0034] Boolean is a type in the object-oriented language Java, which means Boolean type. The so-called Boolean type is a type that has only two states, namely true and false mentioned below. A Boolean type is either true or false.

[0035] Object is a type of object-oriented language Java. Object is the base class of all classes in Java, that is, all classes in Java inherit from Object.

[0036] Figure 3 Here, Boolean and Object represent the types of return values ​​of member methods respectively.

[0037] areItemsTheSame, areContentsTheSame, and getChangePayload are the member methods of the UpdateDataDiffItemCallback class described below. UpdateDataDiffItemCallback is an abstract class that must be inherited by other classes to implement its functions.

[0038] Depend on Figure 3 It can be seen that areItemsTheSame and areContentsTheSame are italic. The italic bodies in this class diagram indicate that these two methods are abstract methods and do not have default implementations. They need to be implemented by a user-defined class that inherits from UpdateDataDiffItemCallback.

[0039] The getChangePayload is not italic, which means it has a default implementation. Users can overload this member method to implement user-defined functions, or they can not overload it and use its default implementation.

[0040] getChangePayload is mainly used to obtain the changes of a single item. The default implementation returns a null value. Considering that users may not need such a fine-grained update operation and only need to be refined to the item level, users can make their own choices. If users need very fine-grained update operations, they can just overload the getChangePayload() method.

[0041] like Figure 3 As shown, the class diagram of the difference calculation method is as follows. This class diagram contains two classes:

[0042] 1. UpdateData is the base class of the data type that the user should provide to the system, that is, the basic type of data mentioned above. The custom data type that the user passes into the system should inherit UpdateData.

[0043] The data member variable in UpdateData is the data collection of the user list, which contains a generic parameter T. By specifying T as a different type, the user can construct data containing data collections of different types.

[0044] At the same time, since users can inherit UpdateData, UpdateData can be expanded, such as adding member variables, including more variables that will cause changes to the list. Suppose this variable is a. When the variable changes, passing in a new UpdateData containing the new a can update the view, and only one update is required. The method provided by the original Android system requires a to be included in the list item data. If a changes, all list items must be updated to update the view.

[0045] 2. UpdateDataDiffItemCallback is the base class for comparison operations of data types that users should provide, that is, the data comparison operations mentioned above. The comparison operations that users provide to the system should inherit from UpdateDataDiffItemCallback.

[0046] UpdateDataDiffItemCallback contains three member methods. Their input parameters are unified as oldItem, newItem, oldUpdateData, and newUpdateData. These parameters will be automatically passed in when the system calculates the difference. Users do not need to pass them in. Users need to use these parameters to implement the corresponding member methods to define the comparison operation.

[0047] The above input parameters are described as follows:

[0048] 1. oldItem refers to the item in the old data set in this update operation, and the data set is the data in UpdateData;

[0049] 2. newItem refers to the entry in the new data set in this update operation;

[0050] 3.oldUpdateData refers to the old data in this update operation;

[0051] 4.newUpdateData refers to the new data in this update operation.

[0052] oldItem and newItem are mainly used for comparison between old and new data set entries, and oldUpdateData and newUpdateData are mainly used for comparison between other variables that will cause changes in the list.

[0053] The three member methods contained in UpdateDataDiffItemCallback are described as follows:

[0054] 1.areItemsTheSame() determines whether the new and old items are essentially the same. If they are essentially the same, it returns true, otherwise it returns false.

[0055] 2.areContentsTheSame() is used to determine whether the new and old entries are exactly the same. If they are exactly the same, it returns true, otherwise it returns false.

[0056] 3. getChangePayload() is a method for obtaining the difference between the new and old entries when they are essentially the same but not exactly the same.

[0057] Essentially the same means that the key members of the data of this entry have not changed. For example, if the ID of a person in a business card has not changed but only his / her avatar and nickname have changed, then they are considered to be essentially the same.

[0058] Identical means that all members of the data for this entry have not changed;

[0059] The system will first execute the member method areItemsTheSame() to determine whether the new and old items are essentially the same; only when the new and old items are essentially the same will the member method areContentsTheSame() be executed to determine whether they are exactly the same, because if two items are not essentially the same, then they certainly cannot be exactly the same.

[0060] When the data is essentially the same but not exactly the same, the system will automatically call the getChangePayload() method to obtain the differences. For example, in the business card above, the system will call getChangePayload() to obtain the changed avatar and nickname, so as to accurately update the business card. That is, only the avatar and nickname of the business card will be updated, and the remaining contents of the business card, such as contact information, will not be updated.

[0061] Through the new and old data, users can implement three member methods according to their business content, thereby defining different comparison operations, that is, which members' changes will cause the entries to be essentially different; when the entries are essentially the same but not exactly the same, what kind of local update data can be provided by the user, thus ensuring flexibility under different business contents.

[0062] UpdateDataDiffItemCallback has two generic parameters: D and U;

[0063] Where D is the type of the entry in the data set in the user-defined data type, that is, T in UpdateData above, and U is the UpdateData corresponding to D;

[0064] By making clever generic designs and using generic mechanisms to set D and U as the entry types of the corresponding user data sets and user-defined data types, the problem of insufficient scalability of the original technology can be solved and any user-defined data type can be adapted.

[0065] Step 2: The system receives new data provided by the user;

[0066] Step 3: The system increments the internal running version as the running version for this data update;

[0067] The reason for updating the internal running version here is that the subsequent difference calculation operation is an asynchronous operation. During the execution of the data difference, the user may also pass in a new version of the data again. By comparing the two running versions, it can be determined whether the updated data is the data that the user really needs to update, thereby preventing confusion in the user view.

[0068] Step 4: Check the memory addresses of the new and old data sets of the user. If the memory addresses of the two are the same, it is considered that the user data has not changed and does not need to be updated, and the update operation ends;

[0069] Step 5: Check whether the user's new data set is empty and the old data set is not empty. If so, it means that the user has cleared the data. In this case, you can perform a quick delete operation without performing a difference calculation. After the quick delete operation is completed, perform a view update to end the update operation.

[0070] Step 6: Check whether the user's new data set is not empty and the old data set is empty. If so, it means that the user has only performed a data addition operation. In this case, you can perform a quick addition operation without performing a difference calculation. After the quick addition operation is completed, perform a view update to end the update operation.

[0071] Steps 4, 5, and 6 are called quick comparisons, that is, they do not need to perform difference calculations in the end, and directly end the update operation or perform view updates after performing deletion or addition operations to end the update operation. Since difference calculation is a relatively resource-intensive operation, performing quick comparisons first can minimize resource consumption.

[0072] Step 7: Switch to the background thread and call the difference calculation algorithm provided by the Android system to perform difference calculation;

[0073] Step 8: After the difference calculation is completed, switch to the main thread and check whether the current running version is consistent with the running version inside the system: if the current running version is inconsistent with the running version inside the system, it means that a data update operation has been performed during the calculation, and the result of this difference calculation is discarded; if the current running version is consistent with the running version inside the system, it means that no data update operation has been performed during the calculation, and the result of this difference calculation is the result that the user really needs, and the result of this difference calculation is used to perform a view update.

[0074] This makes it possible to switch threads when calculating differences without causing the user's view to display content that does not need to be updated, thereby preventing view confusion.

[0075] like Figure 2 As shown, the process of difference calculation of the present invention is:

[0076] After receiving new data, the internal running version number is first incremented, which will be used in subsequent difference calculations;

[0077] Then, the new and old data are quickly compared. If both the new and old data point to the same memory address, it is considered that they have not changed. If the new data set is empty and the old data set is not empty, a quick delete operation is performed and then a view update is performed. If the old data set is empty and the new data set is not empty, a quick add operation is performed and then a view update is performed. None of the above operations perform difference calculations that require large computing resources.

[0078] If the conditions for quick comparison are not met, then switch to the background thread and perform difference calculation. After the difference calculation is completed, switch back to the main thread to check whether the running version before the difference calculation is performed is the same as the current internal running version. If they are not the same, it means that the user has updated the data again and the result of the current difference calculation needs to be discarded; if the two running versions are the same, it means that the current data is the latest data given by the user, and the result of this difference calculation is used to update the view.

[0079] The present invention supports custom data types: in order to solve the problem of scalability of data types, only a basic type is provided for this purpose, which only includes one data collection field. Users can expand this basic type to construct their own custom types according to specific business conditions; for this basic type, a set of methods for adapting user custom types through generic technology is provided, allowing users to customize the difference calculation method of the data, so that users can customize the incoming data for different business scenarios, greatly improving the scalability of the data; at the same time, the provided difference calculation method passes in new and old data, so that the user can change a field in the new data to drive multiple list entries to change, eliminating the waste of performance and resources caused by the need to update multiple mappings.

[0080] The present invention provides basic data types for difference calculation data, so as to facilitate users to expand for different business scenarios; and by improving the difference comparison method, it supports that external conditions can drive multiple list entries to be updated only once without updating multiple mapping values.

[0081] The above implementation modes are not limitations of the present invention, and the present invention is not limited to the above examples. Changes, modifications, additions or substitutions made by technicians in this technical field within the scope of the technical solution of the present invention also belong to the protection scope of the present invention.

Claims

1. An Android list accurate update method, characterized by: The updating method comprises the following steps: Step 1: The system receives old data from the user according to business needs, including: the system receives the custom data type inherited from UpdateData, and the system receives the comparison operation between the new and old data inherited from UpdateDataDiffItemCallback; UpdateData is the base class of the data type that users should provide to the system, that is, the basic type of data. The custom data type that users pass into the system should inherit UpdateData; the data member variable in UpdateData is the data collection of the user list, which contains a generic parameter T. By specifying T as a different type, users can construct data containing different types of data collections; users extend UpdateData by adding member variables. When the variable changes, a new UpdateData containing the new variable can be passed in to update the view; UpdateDataDiffItemCallback is the base class for the comparison operation of the data type that the user should provide, that is, the data comparison operation. The comparison operation provided by the user to the system should inherit from UpdateDataDiffItemCallback; UpdateDataDiffItemCallback contains three member methods: areItemsTheSame, areContentsTheSame, getChangePayload, getChangePayload is used to obtain the difference between the old and new items in the list; the incoming parameters are unified as oldItem, newItem, oldUpdateData, newUpdateData; oldItem refers to the item in the old data set in this update operation, and the data set is the data in UpdateData; newItem refers to the item in the new data set in this update operation; oldUpdateData refers to the old data in this update operation; newUpdateData refers to the new data in this update operation; Step 2: The system receives new data provided by the user; Step 3: The system increments the internal running version as the running version for this data update; Step 4: Check the memory addresses of the user's new and old data sets; Step 5: Check whether the user's new data set is empty and the old data set is not empty; Step 6: Check whether the user's new data set is not empty and the old data set is empty; Step 7: Switch to the background thread and call the difference calculation algorithm provided by the Android system to perform difference calculation; Step 8: After the difference calculation is completed, switch to the main thread and check whether the current running version is consistent with the running version inside the system; if the current running version is consistent with the running version inside the system, it means that no data update operation was performed during the calculation, and the result of this difference calculation is the result that the user really needs, and the result of this difference calculation is used to perform a view update.

2. The Android list accurate update method according to claim 1, characterized in that: The checking process of step 4 is as follows: if the memory addresses of the new and old data sets are the same, it is considered that the user data has not changed and does not need to be updated, and the update operation is terminated.

3. The Android list accurate update method according to claim 1, characterized in that: The checking process of step five is as follows: if the user's new data set is empty and the old data set is not empty, it means that the user has cleared the data. At this time, a quick delete operation can be performed without performing a difference calculation. After the quick delete operation is completed, a view update is performed to end the update operation.

4. The Android list accurate update method according to claim 1, characterized in that: The checking process of step six is ​​as follows: if the user's new data set is not empty and the old data set is empty, it means that the user has only performed a data addition operation. At this time, a quick addition operation is performed without performing a difference calculation. After the quick addition operation is completed, a view update is performed to end the update operation.

5. The Android list accurate update method according to claim 1, characterized in that: The checking process of step eight is as follows: if the current running version is inconsistent with the running version inside the system, it means that a data update operation has been performed during the calculation period, and the result of this difference calculation is discarded.

Citation Information

Patent Citations

  • Method for implementing dynamic update of Java program

    CN101174217A

  • Data updating method and system for view list in list control

    CN105549973A

  • Method for updating UI in asyncronous thread

    CN106775699A

  • Icon updating method and related device

    CN110333920A

  • Status bar automatic replacement method based on mobile equipment

    CN110858858A