-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,825
  • 3
  • 26
  • 43

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,539
  • 5
  • 33
  • 55