Overriding pre / post is done in AsyncTask and calling super.onPre / PostExecute

Is it mandatory to call super.onPreExecute when overriding onPreExecute in AsyncTask? What does AsyncTask.onPreExecute and other methods actually do? Same question for onPostExecute and onCancelled

public class MyAsyncTask extends AsyncTask<Void, Void, Boolean> 
{

@Override
protected void onCancelled(Boolean result) {

    super.onCancelled(result);   //<-DO I HAVE TO?

            //My onCancelled code below


}

@Override
protected void onPostExecute(Boolean result) {

    super.onPostExecute(result);  //<-DO I HAVE TO?

            //My onPostExecute code below
}

@Override
protected void onPreExecute() {

    super.onPreExecute();  //<-DO I HAVE TO?

            //My onPreExecute code below

}

@Override
protected Boolean doInBackground(Void... params) {

    return null;
}
+3
source share
2 answers

No, you do not need to call super. Here is the source.

As you can see, the default implementation does nothing.

/**
* Runs on the UI thread before {@link #doInBackground}.
*
* @see #onPostExecute
* @see #doInBackground
*/
protected void onPreExecute() {
}

/**
* <p>Runs on the UI thread after {@link #doInBackground}. The
* specified result is the value returned by {@link #doInBackground}.</p>
*
* <p>This method won't be invoked if the task was cancelled.</p>
*
* @param result The result of the operation computed by {@link #doInBackground}.
*
* @see #onPreExecute
* @see #doInBackground
* @see #onCancelled(Object)
*/
@SuppressWarnings({"UnusedDeclaration"})
protected void onPostExecute(Result result) {
}
+8
source

No, we don’t have to redefine the   onPreExecute and onPostExecute methods.

onPreExecute doInbackground. , . doInbackground.

doInbackground , , , , - . . , .

onPostExecute doInbackground, , Webservice.

OnCancelled cancel (boolean). isCancelled(), true.

. , .

+2

All Articles