-2

I have found many answers to cancel an AsyncTask, to set object.cancel(true) and in do in background method check

for (int i = 0; i < appState.getAvailableText().length;i++){

  if(isCancelled()){
                break;
            }
            //Do your updating stuff here
        }

But in my Asynctask there is no for loops or switch cases ,hw can i Stop or Cancel the AsyncTYask background process by clicking a button???

Jack
  • 1,644
  • 2
  • 17
  • 42

1 Answers1

2

On your button click write the code

task.cancel(true);

where task is the reference of the async task you have created and started

Gopal Singh Sirvi
  • 4,245
  • 5
  • 28
  • 51