Associating responses with specific requests using Loopj Android Asynchronous Http Client

StackOverflow https://stackoverflow.com/questions/18115139

  •  23-06-2022
  •  | 
  •  

Question

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.

Was it helpful?

Solution

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))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top