Vinny Biscolla Vinny Biscolla - 27 days ago 7
Android Question

how to call AsyncTask sequentially

I have 4 AsyncTask that update my db from the server, but i have a considerable data on each one, so i wanna start each Asynctask after the end of the last one,

by the click of a button, i tried with a "IF" but i didn't get success so i'm posting my code here to let you guys help me in that...

"i just tried to do that, but eclipse didn't compile this code because is wrong, so because my knowledge limitation i thought, in something like that any soluitons ??"

atualiza_base = (Button) findViewById(;
atualiza_base.setOnClickListener(new OnClickListener() {

public void onClick(View arg0) {
new callServiceCliente().execute();
if (calServiceCliente().getStatus == FINISHED) {
new callServiceMaterial().execute();
}else if (callServiceMaterial().getStatus == FINISHED) {
new callServiceProblema().execute();
}else if (callServiceProblema().getStatus == FINISHED) {
new callServiceProcedencia().execute();
Toast.makeText(this, "Database Updated", Toast.LENGTH_LONG).show();

thanks a lot...


Onclick of button start first AsyncTask and then in onPostExecute() method of each AsyncTask (except last AsyncTask) execute next AsyncTask. This will solve your problem.

Make sure you handled your exceptions in doInBackground() method to get call to onPostExecute().