Introducing AsyncTask
AsyncTask
was introduced on the Android platform with Android Cupcake (API Level 3), with the express purpose of helping developers to avoid blocking the main thread. The Async part of the name of this class comes from the word asynchronous, which literally means that the blocking task is not occurring at the same time we call it.
The AsyncTask
encloses the creation of the background thread, the synchronization with the main thread, and the publishing of the progress of the execution in a single construct.
In contrast to the Handler
and Looper
constructs, the AsyncTask
exempts the developer from the management of low level components, thread creation, and synchronization.
AsyncTask
is an abstract class, and as such, must be subclassed for use. At the minimum, our subclass must provide an implementation for the abstract doInBackground
method, which defines the work that we want to get done off the main thread.
protected Result doInBackground(Params... params)
The doInBackground...