Asynctask Goes Into Wait State
I want to cancel the Async Task on the particular condition. I am doing the following stuff: MyService.java .... if(condition){ asyncTask.cancel(true); // its return the true as
Solution 1:
AsyncTask is a piece of work for PoolExecutor. When you execute your first task Executor creates first thread and executes your task on it. After task execution is finished the thread is not deleted. It starts waiting for a new task.
So it is normal to see AsyncTask thread in wait state.
P.S. It's better not to use AsyncTask for longtime operation. Use your own executor or thread.
P.P.S. AsyncTask uses single thread executor since 4.x. Be careful )
Solution 2:
after you explicitly call asyncTask.cancel(true);
, the onCancelled()
method is called. Try overriding the following method:
@OverrideprotectedvoidonCancelled() {
//what you want to do when the task was cancelled.
}
Post a Comment for "Asynctask Goes Into Wait State"