0

I have no idea how to return from onPreExecute() when some condition happens. for instance:

@Override
    protected void onPreExecute() {
       if(varCancel){
         //Do not execute doInBackground() method
        }
        super.onPreExecute();
    }

the thing is, I want to cancel this process before the method doInBackground() start.

ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
jose
  • 25
  • 3

1 Answers1

1

Use AsyncTask.cancel(boolean mayInterruptIfRunning) to cancel execution of Task.

   if(varCancel){
     //Do not execute doInBackground() method
       this.cancel(true);
    }

Or use class object which is used to call execute() for starting AsyncTask to cancel it:

   if(varCancel){
     //Do not execute doInBackground() method
       <CLASS_OBJECT>.cancel(true);
    }
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213