How to cancel the current request in modification when retrofit.client.UrlConnectionClient is used as a client?

I use the modification for http calls in an Android application and retrofit.client.UrlConnectionClient as a client when creating the adapter.

RestAdapter.Builder builder = new RestAdapter.Builder() .setEndpoint(url) .setLogLevel(RestAdapter.LogLevel.FULL) .setClient( new Client.Provider() { public Client get() { return new UrlConnectionClient() { @Override protected HttpURLConnection openConnection(Request request) throws IOException { HttpURLConnection connection = super.openConnection(request); connection.setConnectTimeout(connectionTimeout); return connection; } 

I wanted to set a timeout to use UrlConnectionClient as my client. I could not find a way with other clients such as OkHttp.

Question: how can I cancel the current request?

I saw a similar entry @ Using Square's RetoFit Client, can I cancel the current request? If so, how? but my code will become really complicated if I try to add my own artists and try to cancel the request using this. I see if there is a slightly better way with my existing code.

I also see that Retorofit V2.0 has a Retry and Cancel plan, but I'm not sure when it will be released. https://github.com/square/retrofit/issues/297

Help is needed! In fact, I also need a way to repeat with the same code.

+5
source share
1 answer

It has been available since 2.0.0-beta2 ( https://github.com/square/retrofit/releases/tag/parent-2.0.0-beta2 ). I don't know if there is a document that explains this, but here is a link to the API:
http://square.imtqy.com/retrofit/2.x/retrofit/retrofit/Call.html#cancel--

The 'Call' API also allows you to retry the 'Clone'ing request.

+3
source

All Articles