Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Schedule multiple async task in android

I want to schedule or queue to execute Multiple AsyncTask in background. I have a AsyncTask for HTTP post request that is running in Service, At the same time i make a one more HTTP request in UI thread of AsyncTask.

UI thread taking too long time to execute, because already one thread is running in service. How to resolve this problem.?

I need to Pause a service thread and I want to execute UI thread first and then restart a service thread again for AsyncTask.

Thanks in advance

like image 948
Seetha Avatar asked Apr 01 '14 13:04

Seetha


1 Answers

As AsyncTasks can share a single thread I would try decoupling them by calling:

my_task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[])null);

in place of my_task.execute((Void[])null)

as described in this answer: Android SDK AsyncTask doInBackground not running (subclass)

Another way would be to use Executor framework and ThreadPoolExecutor.

like image 126
atok Avatar answered Oct 05 '22 11:10

atok