Method for optimizing APP request equipment list of Android internet of thingsTechnical Field
The invention relates to the technical field of Internet of things, in particular to a method for optimizing an APP request device list of an Android Internet of things.
Background
Can involve equipment management in thing networking APP, the equipment list comprises a series of equipment to the thing networking family is looked after as the example, and the thing networking equipment that probably includes has air conditioner, desk lamp, socket, (window) curtain etc.. In the actual production process, the internet of things devices are not always connected to the same internet of things platform, for example, a table lamp is from a millet internet of things platform, an air conditioner is from an ali internet of things platform, and the air conditioner is from a factory built-in platform, so that when a service server retrieves the device lists, great network communication pressure is generated, and the load of a service end is seriously improved by frequent device list acquisition. In the internet of things APP, due to the reason that a user frequently switches pages, the problem that the equipment list of the internet of things is frequently requested, the pressure of a server is too high, the waiting time of the user is long, and the equipment list cannot be acquired when the request is overtime is caused.
Disclosure of Invention
The invention aims to provide a method for optimizing an APP request device list of an Android internet of things, which is used for solving the problems of high server pressure and overtime request caused by frequent device list acquisition or frequent page switching of an APP user side of the internet of things in the prior art.
The invention solves the problems through the following technical scheme:
a method for optimizing an APP request device list of an Android Internet of things comprises the following steps:
step S1: when the equipment list is acquired from the server, acquiring a timestamp of the equipment list acquired last time from the local;
step S2: comparing the current time with the timestamp of the device list acquired last time, judging whether the time interval is greater than the specified time, if so, executing the step S3, otherwise, executing the step S4;
step S3: the remote interface of the equipment list is obtained from the server side, the server side returns the equipment list to the APP interface to complete interface data updating, and meanwhile the equipment list is stored to the local and a timestamp mark is added;
step S4: and acquiring the last stored equipment list and time information from the local and returning to the APP interface to complete interface data updating.
The invention adds time interval judgment, and selects to execute local acquisition or acquisition from the server interface according to the time interval. Alleviate the pressure that the server side obtained the equipment list, APP end reduces the time that the user waited for simultaneously, promotes user experience.
And the server returns the device list to the APP interface by calling the getDevice () method.
Storing the device list to local is accomplished by calling the setDevice () method.
Compared with the prior art, the invention has the following advantages and beneficial effects:
according to the method and the device, a timestamp adding mode is adopted, the device list data is stored to the local, if the device calls the acquisition device list again within a specified interval (for example, 10 seconds), the device list is acquired from the local storage, the pressure of the server side for acquiring the device list can be relieved through the judgment of the timestamp, meanwhile, the waiting time of a user is reduced by the APP side, and the user experience is improved.
Drawings
FIG. 1 is a flow chart of the present invention.
Detailed Description
The present invention will be described in further detail with reference to examples, but the embodiments of the present invention are not limited thereto.
Example (b):
with reference to fig. 1, a method for optimizing an Android internet of things APP request device list is disclosed, where when an internet of things APP switches an interface or performs other operations, a getDevice () method is called many times in a short time, when an internet of things APP page switches, a device list needs to be obtained to update an interface display, at this time, a getDevice () method is adopted to obtain a device list and a timestamp obtained last time from local data, and a method for obtaining the timestamp and the device list can be implemented by using the following codes:
SharedPreferences sp=AppManager.appContext().getSharedPreferences
(SHARED_NAME,Context.MODE_PRIVATE);
String timestamp=sp.getString("timestamp",time);
String devices=sp.getString("devices",devices);
wherein timestamp is a timestamp, and devises is a json character string corresponding to the device list.
If the acquired time interval (currenttime-time) is greater than the specified time (such as 10s), acquiring a device list from the acquisition server, wherein the device list is usually a device list interface provided by an http access server; the server returns the data list to the upper-layer getDevice () method, calls the setDevice () method to store the device list to the local, and adds a timestamp mark, wherein the specific android implementation code is as follows:
SharedPreferences
sp=AppManager.appContext().getSharedPreferences(SHARED_NAME,Context.MODE_PRIVATE);
SharedPreferences.Editor editor=sp.edit();
editor.putString("timestamp",time);
editor.putString("devices",devices);
wherein timestamp is a timestamp, and devices is a json character string corresponding to the device list; returning the getDevice () method to the APP interface, completing the interface data update, and ending the process;
if the time interval is less than the specified time interval 10s, the Internet of things APP locally acquires the last stored equipment list and time information and returns the list and the time information to the getDevice () method, the getDevice () method returns the interface of the Internet of things APP, the interface data updating is completed, and the process is finished.
Although the present invention has been described herein with reference to the illustrated embodiments thereof, which are intended to be preferred embodiments of the present invention, it is to be understood that the invention is not limited thereto, and that numerous other modifications and embodiments can be devised by those skilled in the art that will fall within the spirit and scope of the principles of this disclosure.