1

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.

HjK
  • 3,513
  • 1
  • 17
  • 23

1 Answers1

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