简体   繁体   English

提高数据通话的速度性能

[英]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. 我正在从Android应用程序对Web服务进行API调用,问题是它返回大约22000条记录,我将每个记录转换为一个对象后将其加载到一个数组中,然后将该数组分配给ListView。 What is the fastest/best way to fetch this data from the web service? 从Web服务获取此数据的最快/最佳方法是什么? (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 ; 请尝试使用Android Query ; specifically, see the section entitled Asynchronous Network . 具体来说,请参阅标题为异步网络的部分。

This AQuery library ( AndroidQuery ) is lightweight, and requires only 1 jar SMALL jar file. 这个AQuery库( AndroidQuery )是轻量级的,只需要1个jar的SMALL jar文件。 It can be used with Maven or Gradle Android projects as well. 它也可以与Maven或Gradle Android项目一起使用。 It allows you to EASILY fetch XML or JSON data from a remote server in either asynchronous or synchronous fashion. 它允许您以异步或同步方式轻松地从远程服务器获取XML或JSON数据。 I have used it many times with a JSON back-end, and it is a real timesaver. 我已经多次使用它与JSON后端,它是一个真正的节省时间。

This library also allows you to specify a ProgressBar that will automatically appear and disappear during the network download process. 此库还允许您指定在网络下载过程中自动显示和消失的ProgressBar

Here is an example of an HTTP call to a JSON back-end, asynchronously: 以下是异步对JSON后端进行HTTP调用的示例:

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). AQuery还可以简化Android编程的其他方面(例如在许多场景中消除findViewById()调用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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