The problem I have is concerning two separate Asynctask classes. The first asynctask uses a network operation in doInBackground method
HttpResponse httpResponse = httpClient.execute(httpPost);
while the other is a thread for loading images with a progressDialog.
so what happens is if I am using a slow internet connection (so that means the first asynctask hasn’t finished yet) and then go directly to the second asynctask, the second class will wait until the first one is finished.
btw, right after I call the first asynctask I directly finish the activity and call another one does this have to do with anything?
tl;dr version:
second asynctask won’t do the doinbackground process until the first asynctask is done
I know this because the progress dialog is shown for a long time (which I show it in preExecute and dismiss it in postexecute)
EDIT:
the first asynctask involves waiting for a response from the net. so while there isn’t a response the second asynctask won’t do its doinbackground process.
EDIT 2:
Is there a way for me to properly use these 2 asynctask so the second one won’t have to wait for the first to finish?
I had same problem in my app – i needed to run 4 AsyncTasks concurrently in any Android version (from 2.1 – to 4.2). But from Honeycomb, AsyncTasks run in serial.
So i had wrote AsyncTaskExecutor – it can runs AsyncTasks concurrently on any Android version.
Take a look:
AsyncTaskExecutor
It takes all work for running AsyncTask concurrently on any Android OS version, it is better that using:
Because AsyncTask.THREAD_POOL_EXECUTOR available only on api >= 11; I`m using own threadPoolExecutor instance
With AsyncTaskExecutor you just need to write:
And that is all. No errors on Android 2.x, 3.x and 4.x
P.S. I am sorry for copying my answer from other question, but I think, it will be helpful