Home » Android » android – Why use Retrofit with AsyncTask?

android – Why use Retrofit with AsyncTask?

Posted by: admin June 16, 2020 Leave a comment


Few days ago when I tried to learn how to use Retrofit, I found some tutorials that says on some occassions, we should use ASyncTask together with Retrofit. This puzzles me because my impression was we use Retrofit to avoid using ASyncTask. And now I’ve understood Retrofit quite well (enough to use it and change all my ASyncTask codes to Retrofit), I still haven’t find a good excuse or reason to use ASyncTask with Retrofit. Or am I missing anything here?

Btw I saw at least 3 different tutorials that mention on using Retrofit with ASyncTask, but I couldn’t find it anymore. I could only find 1, http://karanbalkar.com/2014/12/tutorial-94-using-retrofit-for-android/

How to&Answers:

The cited tutorial uses synchronous calls. For synchronous calls it makes sense to put them into an AsyncTask.

However, since Retrofit also supports asynchronous calls, it is easier to use them directly without an AsyncTask.