I am using Retrofit 2.4.0 to send requests to a server. But sometimes server blocking my request if it has a similar timestamp in milliseconds with another request. I need to send request one at a time:
- Request A is sent
- Request B waits until the response for Request A received
- Request A completes with success or error
- Request B is sent
Is it possible to create such queue with Retrofit and OkHttp libraries?
transitive verb. : to furnish (something, such as a computer, airplane, or building) with new or modified parts or equipment not available or considered necessary at the time of manufacture. : to install (new or modified parts or equipment) in something previously manufactured or constructed.
(of new or modified parts, equipment, etc.) to fit into or onto existing equipment. to replace existing parts, equipment, etc., with updated parts or systems. noun. something that has been retrofitted. an instance of updating, enlarging, etc., with new or modified equipment: A retrofit could save thousands of dollars.
Retrofit is a type-safe HTTP networking library used for Android and Java.
Call is a method to request to the webserver/API to get data.(Based on my understanding) Follow this answer to receive notifications.
I decided to use Dispatcher's setMaxRequests method to send request one at a time:
Dispatcher dispatcher = new Dispatcher();
dispatcher.setMaxRequests(1);
OkHttpClient client = new OkHttpClient.Builder()
.dispatcher(dispatcher)
.build()
For your requirement, you can simply use Android AsyncTank
and onPostExecute()
. You can call your request B after getting the response of request A.
I feel no need to use Retrofit or OkHttp libraries. These libraries are useful when you send multiple requests at the same time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With