2

I'm using The Loopj Android Asynchronous HTTP Client to send multiple HTTP requests asynchronously.

I'm using a static AsyncHttpClient as suggested and sending multiple HTTP posts and receiving responses on an anonymous class. The problem is that when a request comes back I don't know how to tie it back to the original request.

For instance, in a caching situation, when I send a post and receive a 200 OK I need to be able to know which request that response is for so I can mark it as successfully sent.

joao2fast4u
  • 6,868
  • 5
  • 28
  • 42
scoleman2272
  • 358
  • 6
  • 18

1 Answers1

5

Try this:

public class MyAsyncHttpResponseHandler extends AsyncHttpResponseHandler {

    private String requestId;

    public AsyncHttpResponseHandler(String requestId) {
        this.requestId = requestId;
    }

    @Override
    public void onSuccess(String arg0)
    {
        super.onSuccess(arg0);
        // Use requestId here
    }
}

Sending request:

client.get(url, new MyAsyncHttpResponseHandler(requestId))
Sangharsh
  • 2,999
  • 2
  • 15
  • 27