Reputation: 45
Here is my execution:
KlientNameValue kn = new KlientNameValue(getApplicationContext());
ZamowienieNameValue zn = new ZamowienieNameValue(getApplicationContext());
kn.new MyAsyncTask().execute(zam.klient.getNazwa(),zam.klient.getNip(),zam.klient.getAdres());
zn.new MyAsyncTask().execute(zam.getSuma());
for (int i = 0; i < MainActivity.lista_wybranych_towarow.size(); i++) {
TowarZamowienieName tzn = new TowarZamowienieName(getApplicationContext());
tzn.new MyAsyncTask().execute(String.valueOf(MainActivity.valueYouWant),String.valueOf(MainActivity.lista_wybranych_towarow.get(i).getTow_id()),MainActivity.lista_wybranych_towarow.get(i).getTow_ilosc());
}
For one execution it works but for two or more don't what should I do ? I want to add they all have to be executed while on click has place.
Upvotes: 0
Views: 41
Reputation: 6501
This overuse of AsyncTask is really a code smell. I guess that your problem is that your Asynctasks don't get executed in paralel. To execute in paralel on API > 11 use:
new MyAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, PARAMS);
Or even better use a version of this function:
if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ) {
new MyAsyncTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
new MyAsyncTask().execute();
}
More in depth explanation:
Running multiple AsyncTasks at the same time -- not possible?
Upvotes: 1