2

As the title says, I'm having a strange issue with loopj's AsyncHttpClient.

MyObject is a class that contains a link and a value and lista is a List containing 50 MyObject objects.

I need to retrieve header information from 50 links, so I've made a cycle like this:

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());
            }
        });
    }
}

At this point, if I try to exec the app and look at CatLog, I can see that just about 20 or 30 out of 50 request are executed, while the others do not give any feedback (i.e. no timeout exception, no "retrieving informations" debug message nor any other type of message).

If I try to exec again the app, just about 7 or 8 requests will be executed.

If I try to change anything in the code (for example adding a comment) and run it again, it even fails to install on the emulator with the following error:

[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!

Having said that removing the aforementioned piece of code everything else works well, I hope someone could help me to solve it.

Any help would be apprecied. Really thank you in advance!

morten.c
  • 3,414
  • 5
  • 40
  • 45

1 Answers1

2

I have face the same issue. It seems you are using loopj's version 1.4.4. They have this as a known issue in there 1.4.4 version on github. To resolve it you will have to take pull from latest master from : https://github.com/loopj/android-async-http. Once you will pull the latest code, then compile it and generate jar file. Then use this jar instead of v1.4.4 jar. Unfortunately, they have not deployed latest jar with this fix as of now in there releases.

I figured out this issue after lots of research. You can check it on these urls : 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

Hope this will help you. If this answers your question or resolves your issue, please +1 this :)

Keshav Bansal
  • 407
  • 4
  • 6