What is "asynctask"

Asynctask is an Abstract Class used to run methods on a background thread, leaving Thread UI (Main Thread) free. The use of Asynctask is for processes of few seconds, if it is necessary to perform more time-consuming processing, it is advisable to use the options of Apis present in package "java.util.Concurrent", as indicated in the documentation. An Asynctask object has its own life cycle where specific methods are called in a specific order:

  • onPreExecute(): This is the first method called when running execute(Params...);
  • doInBackground(Params...): This method is already called after the onPreExecute() method has been completed. This is where the process will be performed on a separate thread from the Main Thread;
  • onProgressUpdate(Progress...): This method is called when the publishProgress(Progress...) method is triggered;
  • onPostExecute(Result): Finally, this method is called right after the end of the onInBackground(Params) method...);