2

I am assigning the tag to OkHttp Request like,

Request request = new Request.Builder()
    .url(url)
    .tag(requestTag)
    .build();

and I can cancel that particular request by that using

public static void cancel(Object tag) {
    for (Call call : getClient().dispatcher().queuedCalls()) {
        if (tag.equals(call.request().tag())) call.cancel();
    }
    for (Call call : getClient().dispatcher().runningCalls()) {
        if (tag.equals(call.request().tag())) call.cancel();
    }
}

But how to assign multiple tag to request because I have to track the request and if any request has timeout then I have to cancel the related tag request

Any idea?

Jaymin Panchal
  • 2,797
  • 2
  • 27
  • 31

1 Answers1

1

Change your application to always use a Set for its tags. In your canceling code you’ll need to downcast.

Jesse Wilson
  • 39,078
  • 8
  • 121
  • 128
  • I had a similar question as the OP. Can you please explain your answer in more detail? – tbag Nov 03 '17 at 00:32