I have a problem with the AsyncTask
. Sometimes the doInBackground()
method is not called after onPreExecute()
.
I know this questio
It happened to me one time because some of my tasks were blocked in the doInBackground()
(which is obviously impossible with the code sample you pasted).
The default pool size on Android for the THREAD_POOL_EXECUTOR was 5 the last time I have checked. So if you execute more than 5 tasks at the same time the next ones will wait until a task is finished.
It's the only case I known to prevent a doInBackground()
call.
Finaly I found a solution to the problem.
Instead of execute the asyncTask with the *AsyncTask.THREAD_POOL_EXECUTOR*, I instanciate my own ThreadPoolExecutor with a large corePoolSize and maximumPoolSize:
int corePoolSize = 60;
int maximumPoolSize = 80;
int keepAliveTime = 10;
BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>(maximumPoolSize);
Executor threadPoolExecutor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.SECONDS, workQueue);
And ...
asyncTask.executeOnExecutor(threadPoolExecutor);
I don't know if this is a good bugfix but with this, doInBackground() is always called. As you said, I supose that the problem was that *AsyncTask.THREAD_POOL_EXECUTOR* could not manage as much asyncTasks as I gave to it.
Thank you guys
Your code looks fine.
You can only run async tasks once. I'm guessing that you are trying to run them several times.
Create another instance and try again.
If it doesn't works, check the logcat and post it here if it's not enough for you to fix it.