Guy
Guy

Reputation: 6522

Cancel all Retrofit requests at once?

I know that individual Retrofit requests can be cancelled at any time by simply calling retrofitCall.cancel();

But I need a way to cancel all ongoing requests at once. Is it possible? I haven't found anything like it in the documentation.

Upvotes: 14

Views: 11661

Answers (2)

Yu-Hsuan
Yu-Hsuan

Reputation: 505

I found that using OkHttp API to cancel will causing mCall.isCanceled() return false.

Upvotes: 0

Viktor K
Viktor K

Reputation: 2173

You have to keep reference to your shared OkHttpClient.

Than when you want to cancel all requests just call:

client.dispatcher().cancelAll()

Upvotes: 41

Related Questions