Skip to content
Advertisement

Is Android AsyncTask use multithreading because android official web says?

while learning the difference between multi-threading and Concurrency.i follow this stackoverflow answer according to my understanding AsyncTask is just used to on or off the use of main thread{ui thread} while events like http request or fetching data from database. and after task is done main thead is reallocated to the event by AsyncTask task. but Android Official says “An asynchronous task is defined by a computation that runs on a background thread and whose result is published on the UI thread”

now i am confused.

  1. android use multi-theading its just wrapper class for thread management.
  2. C# async and await is diffrent concept.

Advertisement

Answer

An AsyncTask “touches” two threads: Main/UI and the Background one. There are few of its methods that run on Main/UI Thread (onPre/onPostExecute()) and one method that is run on a WorkerThread in background. There is an internal sync/queue between those methods.

Concurrency (async/await) doesn’t (necessarily) use a second thread but uses “moments of when the CPU is free“. Think about this non-real case: if the Main/UI Thread is 100% busy then no any Concurrency could be executed until the Main/UIThread has a bit of “free CPU cycles” to share. Intead, in this last example AsyncTasks will do its job asynchronously without take in count other Threads (and its results will be queued to UI/MainThread to be processed later).

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement