How to Stop AsyncTask in Android

AsyncTask is used for Threading Appliction. In most situation we want to stop in when its in running state. For example when we downloading or uploading file in the middle of process we want to stop the use the following code.
MyAsyncTask objUploader;
if (objUploader != null && objUploader.getStatus() != AsyncTask.Status.FINISHED)
objUploader.cancel(true);
Use the following code in the AsynchTask class method doInBackground()
if (isCancelled())
{
break;
}

Post a Comment

0 Comments