views:

819

answers:

2

In my Activity I use multiple AsyncTask classes.

How to cancel AsyncTask when Activity finishes?

+1  A: 

I don't understand if your "cancel" means rollback but you have a cancel method on the AsyncTask class.

Macarse
After the task is finished I want it to disappear.
Pentium10
+2  A: 

Attempts to cancel execution of this task. This attempt will fail if the task has already completed, already been cancelled, or could not be cancelled for some other reason. If successful, and this task has not started when cancel is called, this task should never run. If the task has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task should be interrupted in an attempt to stop the task.

class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {

        @Override
        protected Long doInBackground(URL... params) {
            // TODO Auto-generated method stub
            return null;
        }

    }

    DownloadFilesTask astDownloadFile = new DownloadFilesTask();
    astDownloadFile.cancel(true);
Rahul Patel