Skip to content
Advertisement

Retrofit: How to wait for response

I have AsyncTask and the doInBackground method inside which, I sending POST request using Retrofit. My code looks like:

JavaScript

The problem is: Retrofit sending request asynchronously and while it, the doInBackground method returning the value. So I need to send a request in the same thread with all executions in the sequence. One by one. And returning from doInBackground occurs after the request finished. How can I send a request in the same thread using Retrofit?

Advertisement

Answer

The Call class has an execute() method that will make your call synchronously.

enqueue() is explicitly for making an asychronous call.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement