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!