I have a series of asyncTasks to be performed one after the other to download pdfs from the server.But sometimes when i minimize the app and then resume it (with downloads in the background) the very next asyncTask to be executed soon after the currently running asyncTask gets stuck in the preExcute ie. the doInBackground isn't being performed. Please help.
Asked
Active
Viewed 557 times
1
-
Cancel the asyncTask when you minimize the app and run it again .... – Md Abdul Gafur Jun 28 '12 at 09:30
1 Answers
2
This is a known issue on AsyncTasks. The default executor for AsyncTasks are SERIAL_EXECUTOR
. You can have 5 AsyncTasks in the queue for this executor. After that, it will stop making new Threads
.
If you would do this:
public void someMethod() {
new MyAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
It would run your AsyncTasks on a different executor that pools your threads. It has a limit of 15. But the best thing is, it runs the threads parallel and the SERIAL_EXECUTOR
puts them in a queue and executes them one by one.

tolgap
- 9,629
- 10
- 51
- 65