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

Thread in Android

Android Age Calculator

How to Open Multiple apps in mobile it same time: multitasking feature in mobile