lobisheet.blogg.se

Retrofit enqueue
Retrofit enqueue










This behavior changed from Retrofit v1 to v2. Let’s move to the point where we execute the actual request. That means, you can still interact with the app itself while waiting for the response.

retrofit enqueue

Synchronous methods provide the ability to use the return value directly, because the operation blocks everything else during your network request.įor non-blocking UI, you have to handle the request execution in a separated thread by yourself. You’ll run into the `NetworkOnMainThreadException` error.

#Retrofit enqueue android

Warning: synchronous requests trigger app crashes on Android 4.0 or newer.

retrofit enqueue

That means the UI blocks during request execution and no interaction is possible for this period. Synchronous methods are executed on the main thread. However, the interface definition for synchronous and asynchronous requests are the same within Retrofit 2. The actual synchronous or asynchronous request is executed differently using the desired method on a later created call object. Within Retrofit 2, every request is wrapped into a Call object. Retrofit 1.9 public interface TaskService getTasks() Retrofit 2 public interface TaskService getTasks() The example below expects a list of tasks as the response when executing the method getTasks. Synchronous requests with Retrofit 1.9 are declared by defining a return type.

retrofit enqueue

Users define the concrete execution by setting a return type (synchronous) or not (asynchronous) to service methods. Retrofit supports synchronous and asynchronous request execution.










Retrofit enqueue