I want to know the difference between FutureTask
and AsyncTask
in android. According to my thinking we can get the current situation in FutureTask. Using ExecutorService
we can create a pool of parallel processes. Same property we can achieve using AsyncTask . I want to know the situation where to use AsyncTask and when to use FutureTask.
I have asked a Question here but not getting any response . Now i think i should change my way of getting webservices data. So i think i should use FutureTask
because they have function like isDone()
and cancel. Please some one guide me any better way to retrieve data from web-services. because my textView set's the adapter too slow.
Or simply i need a way to cancel the running AsyncTasks or replace it with the current. When user press w
it call for the AsyncTask and when he added any word to it in AutotextView it will call thrice for waka
one for wa
and wak
and one for waka
. Is it possible to cancel the running task when user presses another text. See my Question here for Details.
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
.