0

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.

user3310467
  • 45
  • 1
  • 5

1 Answers1

1

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?

Community
  • 1
  • 1
VM4
  • 6,321
  • 5
  • 37
  • 51
  • Do you really need so many tasks runnning in parallel? It seems that mannaging them will be a nightmare. Are you sure you can't get away with only using one AsyncTask that calls the same function on different params? – VM4 Feb 15 '14 at 23:45
  • @V M this is priceless suggestion ! I will make it as you say. Thank you very much – user3310467 Feb 15 '14 at 23:47