【问题标题】:Calling numerous Android loopj AsyncHttpClient HEAD requests, just a random number of them is being executed调用大量 Android loopj AsyncHttpClient HEAD 请求,只是其中的随机数正在执行
【发布时间】:2014-03-05 01:54:30
【问题描述】:

正如标题所说,我在使用 loopj 的 AsyncHttpClient 时遇到了一个奇怪的问题。

MyObject 是一个包含一个链接和一个值的类,而 lista 是一个包含 50 个 MyObject 对象的 List。

我需要从 50 个链接中检索标题信息,所以我做了一个这样的循环:

private static AsyncHttpClient client;


public MyClass(){
    client = new AsyncHttpClient();
    client.setURLEncodingEnabled(true);
}

....

public void foo(List<MyObject> lista){
    for (final MyObject c : lista) {    

        client.head(c.getLink(), new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, org.apache.http.Header[] headers, byte[] responseBody) {

                Log.d("DBG", "retrieving informations");
                int contentlength = Integer.parseInt(headers[3].getValue());
                c.setValue(contentLength);

                Log.d("DBG", "retrivied");

                setView(lista);

            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
                Log.d("DBG", "retrieving informations failed");
                Log.d("DBG", error.toString());
            }
        });
    }
}

此时,如果我尝试执行应用程序并查看 CatLog,我可以看到 50 个请求中只有大约 20 或 30 个被执行,而其他的没有给出任何反馈(即没有超时异常,没有“检索信息”调试消息或任何其他类型的消息)。

如果我再次尝试执行该应用程序,将执行大约 7 或 8 个请求。

如果我尝试更改代码中的任何内容(例如添加注释)并再次运行它,它甚至无法在模拟器上安装并出现以下错误:

[2014-03-05 02:46:28 - Myapp] Failed to install MyApp.apk on device 'emulator-5554!
[2014-03-05 02:46:28 - MyApp] (null)
[2014-03-05 02:46:28 - MyApp] Launch canceled!

话虽如此,删除上述这段代码一切正常,我希望有人能帮我解决它。

我们将不胜感激。 真的提前谢谢你!

【问题讨论】:

    标签: android head loopj android-async-http


    【解决方案1】:

    我也遇到过同样的问题。看来您使用的是 loopj 的 1.4.4 版。他们在 github 上的 1.4.4 版本中将此作为已知问题。要解决它,您必须从 https://github.com/loopj/android-async-http 获取最新的 master 。 一旦你将提取最新的代码,然后编译它并生成 jar 文件。然后使用这个 jar 代替 v1.4.4 jar。不幸的是,到目前为止,他们还没有在该版本中部署带有此修复程序的最新 jar。

    经过大量研究,我发现了这个问题。您可以在这些网址上查看: https://github.com/loopj/android-async-http/issues/455
    https://github.com/loopj/android-async-http/issues/453
    https://github.com/loopj/android-async-http/issues/397
    https://github.com/loopj/android-async-http/issues/398
    https://github.com/loopj/android-async-http/pull/425
    https://github.com/loopj/android-async-http/commit/5ee354db6706562849710b6fcd9b8ec91a3916fd

    希望这会对您有所帮助。如果这回答了您的问题或解决了您的问题,请为此 +1 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多