Hello! Who knows how to kill AsyncTask ? So I found the cancel(boolean) method, but when you use it, the thread is not killed and you need to check isCanceled true or false in doInBackgraund and then interrupt the process. And how to do so at once to kill the process?
- 3the flow must be independently verified within itself, and if it is ordered to cancel, then it must carefully complete its work. - KoVadim
- I normally kill dialog.setOnCancelListener (new OnCancelListener () {public void onCancel (DialogInterface dialog) {appAsync.cancel (false);}}); - katso
1 answer
The cancel method on input accepts a boolean parameter that indicates whether the system can interrupt the thread execution. This is just a label.
That is, further in the doInBackground, you need to independently in the code periodically call the isCancelled method to check periodically . As soon as we execute the cancel method for AsyncTask , isCancelled will return true . And this means that we must independently correctly complete the doInBackground method.
Those. The cancel method is the label that the task should be canceled. The isCancelled method - we ourselves read this label and take actions to complete the task. That is why "one time to kill the process" will not work.
As well as the onCancelled method is called by the system instead of onPostExecute if the task has been canceled.