sanjeev sanjeev - 1 year ago 142
Android Question

running parallel AsyncTask

I have a SplashActivity in my application which do some stuff using AsyncTask when I start my application.

I have also created another AsyncTask which downloads data from the server. Now after I close my application the AsyncTask is still downloading the data.

But when I again start my application my SplashActivity's AsyncTask does not execute its background (doInBackground function) till my downloader AsyncTask is finished, and my application is hanged.

So my question is it that we cant run two AsyncTask parallel? Both AsyncTask are different and doing their own stuff.
Is there a way to do it.

Answer Source

You will need to use a thread pool Executor to execute AsyncTask. Default implementation uses a serial executor running on a single thread

So create a ThreadPoolExecutor and then use

AsyncTask's executeOnExecutor instead of just execute method

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download