AsyncTask enables proper and easy use of the UI thread. This class allows to
perform background operations and publish results on the UI thread without
having to manipulate threads and/or handlers.
4 Steps:
private class LongBackgroundTask extends AsyncTask<Void,Void,Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
//invoked on the UI thread before the task is executed
}
@Override
protected Void doInBackground(Void... params) {
//This step is used to perform background computation that can take a long time
}
@Override
protected void onProgressUpdate(Progress...) {}
//This method is used to display any form of progress in the user interface while the background computation is still executing
@Override
protected void onPostExecute(Void aVoid) {
//invoked on the UI thread after the background computation finishes.
}
AsynckTask 3 parameters:
Params, the type of the parameters sent to the task upon execution.
Progress, the type of the progress units published during the background computation.
Result, the type of the result of the background computation.
Comments
Post a Comment