In brief, AsyncTask
contains a few methods which may be helpful:
onPreExecute
:
- This method is the first block of code executed when calling
asyncTask.execute();
(runs on mainUIThread).
doInBackground
:
- Here you put all the code which may suspend you main UI (causes hang for your application) like internet requests, or any processing which may take a lot of memory and processing. (runs on background thread), contains one parameter taken from the
asyncTask.execute(ParameterType parameter);
onPostExecute
- Runs after
doInBackground()
. Its parameter is the return value of thedoInBackground
function, and mainly you put the changes in UI need to be done after the connection is finished (runs on mainUIThread)