anroid 取消 AsyncTask

Cancelling a task

A task can be cancelled at any time by invoking cancel(boolean). Invoking this method will cause subsequent calls to isCancelled() to return true. After invoking this method, onCancelled(java.lang.Object), instead of onPostExecute(java.lang.Object) will be invoked after doInBackground(java.lang.Object[]) returns. To ensure that a task is cancelled as quickly as possible, you should always check the return value of isCancelled() periodically from doInBackground(java.lang.Object[]), if possible (inside a loop for instance.)



取消一个异步任务:

一个任务可以通过调用 cancel(boolean)而被随时取消,调用此方法会导致随后调用isCancelled()返回true,调用此方法后,onCancelled(java.lang.Object)会取代onPostExecute(java.lang.Object) 在doInBackground(java.lang.Object[]) 方法返回后被调用。为了确保尽可能快的知道任务被取消,可能的话,你应该在doInBackground(java.lang.Object[])中周期性地检查isCancelled()的返回值(例如在循环中)。


你可能感兴趣的:(anroid 取消 AsyncTask)