2

I'm trying to call onCancelled() in AsyncTask. For cancelling a task I am invoking cancel(true). In my doInBackground, I have written this,

try {
        response= HttpService.doServerRequest(params);

    } catch(Exception e){
       //pd.dismiss();
         task.cancel(true);
         if(task.isCancelled()){
            CustomException.onException((Activity) this.context);
         }
   }

And I have override this method which will be called when task is cancelled.

@Override
protected void onCancelled() {
            CustomException.onException((Activity) this.context);
}

But this onCancelled() is not getting called after cancellation.

Please help.

Thanks.

Android
  • 183
  • 1
  • 13
  • try to call just `cancel` instead of `task.cancel` and copy the rest of the code `if(task.isCancelled()){ CustomException.onException((Activity) this.context); }` to `onPostExcute` method – Omar HossamEldin Apr 03 '14 at 08:59
  • did you check this : http://stackoverflow.com/a/13851360/1332870 – CompEng Apr 03 '14 at 08:59
  • http://stackoverflow.com/questions/4748964/android-cancel-asynctask-forcefully – Sree Apr 03 '14 at 09:05

0 Answers0