AsyncTask - siddhpatil6/Kotlin-AsyncTaskExample GitHub Wiki

AsyncTask -

Definition -

Updating UI from the separate thread is the most encountered scenario. for such scenarios, Android has provided us API which is called as AsyncTask.

AsyncTask Have four methods -

  1. PreExecute
  2. DoInBackground (must override)
  3. ProgressUpdate
  4. PostExecute

Explanation -

doInBackgrond -

Android runs long running task in doInBackground, android runs doInBackground in Separate Thread. Android Itself creates the separate thread for doInBackground.

PreExecute -

It is initialised before doInBackground Anything initialisation is to be done before performing any task in the background is to be done in PreExecute.

PostExecute

it is called after DoInBackground It executes on UI Thread. after performing task in background to update result on UIThread PostExecute Method get called.

ProgressUpdate

If You want to continually update UI of UIThread from doInBackground and also wants to come back and perform task in doInBackground. to do that you have to call publishProgress from doInbackground