android - How to run multiple AsyncTask? -


i have 2 spinner, each spinner's data loaded database using asynctask

i call asynctasks using this

new populatespinnera().execute(); 

it works if call 1 asynctask 1 spinner

but!

i have 2 spinners, call asynctask each spinner this

new populatespinnera().execute(); // spinner new populatespinnerb().execute(); // spinner b 

i run , app force close

solution?

update!

i inspiration below answer true , false

im using boolean (playing true , false) make 2 spinners generated

first make boolean variable

boolean spn = false; 

then make function check boolean , put on oncreate() function

private void cek(){         if(!spn){             new populatespinnera().execute();         }         if(spn){             new populatespinnerb().execute();         }     } 

on populatespinnera() put 2 lines run second spinner's asynctask

spn = true; cek(); 

and

boom!

it's done :d

you can not have 2 spinner @ time. need use trick in case,

  1. use 1 spinner.
  2. start spinner while initiating first spinner.
  3. use 1 common flag set on postexecute.
  4. before step#3, on postexecute of both asynctask check flag set, if yes cancel spinner.

refer below pseudo code.

postexecute(){       if(taskcompletedflag == true){             //code cancel spinner.             taskcompletedflag = false;       }else{             taskcompledtedflag = true;       } } 

p.s. - in case not aware asynctask initiate first, can use same mechanism on there.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -