Android Run Multiple AsyncTask Same Time

Android Run Multiple AsyncTask Same Time

Problem:
I am trying to excute Multiple asynctask same time(Android Version 4.0.1) but onPreExcute method only called  after that nothing happen.
 
Solution.
AsyncTask uses a thread pool pattern for running the stuff from doInBackground(). The issue is initially (in early Android OS versions) the pool size was just 1, meaning no parallel computations for a bunch of AsyncTasks. But later they fixed that and now the size is 5, so at most 5 AsyncTasks can run simultaneously. 
 
 

–> 

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

TestAsyncTask firstAsync = new TestAsyncTask();

firstAsync.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

 

}

else{

TestAsyncTask firstAsync = new TestAsyncTask();

firstAsync.execute();

 

}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s