Difference between FutureTask and AsyncTask in android
AsyncTask
provides callbacks (onPreExecute
, onProgressExecute
, and onPostExecute
) which are guaranteed to run on the UI thread. AsyncTask is deprecated (thanks chokdee).
FutureTask
provides no callbacks and doesn't know anything about the Android UI thread. In fact, Android apps shouldn't call Future.get()
from the UI thread, because it may block.
Android apps should use Kotlin coroutines. If you're stuck in Java, use FutureTask
.