Skip to content Skip to sidebar Skip to footer

Cancel Asynctask In Android

I would like to cancel an Asynctask in android but I have a problem with my implementation : My code is : private class SynchroTask extends AsyncTask{ private volatile bo

Solution 1:

That's half of implementation of what you have done

   mSynchroTask.cancel(true);

A task can be cancelled at any time by invoking cancel(boolean). Invoking this method will cause subsequent calls to isCancelled() to return true. After invoking this method, onCancelled(Object), instead of onPostExecute(Object) will be invoked after doInBackground(Object[]) returns.

This is what you are missing

To ensure that a task is cancelled as quickly as possible, you should always check the return value of isCancelled() periodically from doInBackground(Object[]), if possible (inside a loop for instance.)

Source : http://developer.android.com/reference/android/os/AsyncTask.html

Post a Comment for "Cancel Asynctask In Android"