Say I am running
new CommentList().execute(url);
If I am in the doInBackground method and I catch a Null value and inside that null value exception I try running the same one again:
new CommentList().execute(url);
Will it stop running the first one?
Can I do this:
if (result == null) {
cancel(true);
}
@Override
protected void onCancelled() {
new CommentList().execute(commentlinkurl);
}
Basically I don’t want the onPostExecute to run if it gets cancelled.
This is not a good idea. You should not be creating new task on a non-UI thread (from within
doInBackgroundmethod).From docs:
Edit based on comments:
You can however start the task again inside
onPostExecuteoronCancelledmethod. You can simply return some specific result to it fromdoInBackgroundor save your Throwable in the AsyncTask member variable to analyze it further: