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;
}

Comments

Popular posts from this blog

Android Content Provider

How to Create blogger website or Blog in Mobile : Complete Tutorial Step by Step

Android Age Calculator