Cancel Queue Request In OKHTTP3

You can cancel current or queue request in OkHTTP3 buy adding a tag to your request and after that, you need to call bellow function to cancel a request for new request most useful if you need to request API on word change, for example, you can create new request when your search word change.

Add a tag to request which we find later for the cancel request

RequestBody body = RequestBody.create(MEDIA_TYPE, postData.toString());Request request = new Request.Builder()
.header("Accept", "application/json")
.header("Content-Type", "application/json")

To cancel Request we can find this tag in our OKHTTP client

for (Call call : client.dispatcher().runningCalls()) {
if (call.request().tag().equals("preRequest")) {
Log.e("cancle", "requestCancel");

That’s it. You can read post here:-


|Published on September 4, 2019


Trinity Tuts

Trinity Tuts