简体   繁体   中英

improving speed performance on a data call

I am making an API call to a web service from the android application the problem is that it returns around 22000 records, I am loading this into an array after i convert each record into an object then assign that Array to a ListView. What is the fastest/best way to fetch this data from the web service? (buffer) ? and what are the best practices for this type of issues.

I would recommend using a library to handle your data call...

Please try using Android Query ; specifically, see the section entitled Asynchronous Network .

This AQuery library ( AndroidQuery ) is lightweight, and requires only 1 jar SMALL jar file. It can be used with Maven or Gradle Android projects as well. It allows you to EASILY fetch XML or JSON data from a remote server in either asynchronous or synchronous fashion. I have used it many times with a JSON back-end, and it is a real timesaver.

This library also allows you to specify a ProgressBar that will automatically appear and disappear during the network download process.

Here is an example of an HTTP call to a JSON back-end, asynchronously:

public void asyncJson(){

    //perform a Google search in just a few lines of code

    String url = "http://www.google.com/uds/GnewsSearch?q=Obama&v=1.0";
    aq.ajax(url, JSONObject.class, this, "jsonCallback");

}

public void jsonCallback(String url, JSONObject json, AjaxStatus status) {

    if(json != null) {
            //successful ajax call
    } else {
            //ajax error
    }

}

AQuery can also simplify other aspects of Android programming (such as eliminating the findViewById() calls for many scenarios).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM