Reputation: 1109
I am offloading many background operations (like web access, and DB operations) to AsyncTasks in order to make my application run faster. It partially works, because the UI does not hang. But it still takes the app a long time to settle (i.e. finish the background tasks).
When looking at the logcat I noticed that all the background tasks (AsyncTask) run one after the other. No concurrency. How can one write a truly multi-threaded application?
Upvotes: 1
Views: 610
Reputation: 1109
Reading the AsyncTask's documentation you can see that indeed Android runs all non-main-thread tasks in a single thread. See "order of execution" in http://developer.android.com/reference/android/os/AsyncTask.html
But there you also have the solution: use executeOnExecutor(java.util.concurrent.Executor, Object[]) with THREAD_POOL_EXECUTOR.
Upvotes: 3