Is Retrofit .execute method is already background task or should I call this method in AsyncTask in retrofit official documentation it mentions that callbacks executed in mainThread, but its not clear if execute method is background task.
Retrofit documentation:
SYNCHRONOUS VS. ASYNCHRONOUS Call instances can be executed either synchronously or asynchronously. Each instance can only be used once, but calling clone() will create a new instance that can be used.
On Android, callbacks will be executed on the main thread. On the JVM, callbacks will happen on the same thread that executed the HTTP request.
call.execute() //not a background task, works in the foreground(synchronous).
call.enqueue() //This is a background task(asynchronous).
call.execute() runs the request on the current thread.
call.enqueue() runs the request on a background thread, and runs the callback on the current thread.
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