Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrofit execute method is it background task

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.

like image 970
LeTadas Avatar asked Feb 25 '26 19:02

LeTadas


1 Answers

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.

like image 111
Navneet Krishna Avatar answered Feb 28 '26 09:02

Navneet Krishna



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!