I'm dealing with problems (memory leak, ui freeze, ...) using loopj (latest version: 1.4.6) to download some large (5m+) text data (complex json encoded objects which contain base64-encoded binary data as one of their fields). here's the base class which extends TextHttpResponseHandler to download data
public class AsyncResponseHandler extends TextHttpResponseHandler {
private final HttpAsyncResultTask asyncResultTask;
private final Logger logger = LoggerFactory.getLogger(AsyncResponseHandler.class);
public AsyncResponseHandler(final HttpAsyncResultTask asyncResultTask){
super("utf-8"); // todo: ...
this.asyncResultTask = asyncResultTask;
}
@Override
public void onFailure(final int i, final Header[] headers, final String s, final Throwable throwable) {
logger.warn("got failure: i: " + i + " , s: " + s + " , t: " + throwable);
asyncResultTask.onFailure();
}
@Override
public void onSuccess(final int i, final Header[] headers, final String s) {
logger.debug("got success: i: " + i + " , s: " + s);
asyncResultTask.onSuccess(s);
}
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBytes) {
super.onSuccess(statusCode, headers, responseBytes);
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBytes, Throwable throwable) {
super.onFailure(statusCode, headers, responseBytes, throwable);
}
}
note that, the HttpAsyncResultTask interface might have multiple implementations based on the given task
Edited well, I changed the approach a little bit by downloading the smaller file chunks of the resource separately (& concurrently); so, now the size of the resource is not the issue. but I'm still getting ANR in my app and with the help of logs, I'm pretty sure that the ANR happens when the application tries to make http calls. these http calls is created within the background service and according to the loopj documentation, it should be async. any ideas on the reason of the ANRs ?