-2

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(R.id.update_button);
    atualiza_base.setOnClickListener(new OnClickListener() {

        @Override
        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...

1

2 Answers 2

2

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().

2

In each AsyncTask class, call the next AsyncTask in the onPostExecute method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.