How to stop asynctask thread in android?

user picture user · Oct 19, 2011 · Viewed 100.2k times · Source

I want to stop a AsyncTask thread from another AsyncTask thread. I have tried like new AsyncTask.cancel(true) to stop the background process but it didn't stop.

Could any one help me on this?

Answer

Yashwanth Kumar picture Yashwanth Kumar · Oct 19, 2011

declare your asyncTask in your activity:

private YourAsyncTask mTask;

instantiate it like this:

mTask = new YourAsyncTask().execute();

kill/cancel it like this:

mTask.cancel(true);