onPostExecute上取消的AsyncTask

onPostExecute上取消的AsyncTask

本文介绍了onPostExecute上取消的AsyncTask的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确实 onPostExecute 执行,如果的AsyncTask 已被取消?

Does onPostExecute execute if the AsyncTask has been cancelled?

如果它确实执行,它是安全地说,我应该总是问,如果该任务已经被取消( isCancelled )的的开始onPostExecute ,做其他事情之前?

If it does execute, is it safe to say that I should always ask if the task has been cancelled (isCancelled) at the start of onPostExecute, before doing anything else?

推荐答案

onPostExecute对取消记录的行为()是Android的2和Android 4之间变化。

The documented behaviour of onPostExecute on cancel() was changed between Android 2 and Android 4.

<一个href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.3.7_r1/android/os/AsyncTask.java#AsyncTask.onPostExecute%28java.lang.Object%29">Android 2.3.7 onPostExecute :

运行doInBackground后在UI线程上。指定的结果是  通过doInBackground返回的值或空,如果任务被取消  或异常发生。

<一个href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/4.0.1_r1/android/os/AsyncTask.java#AsyncTask.onPostExecute%28java.lang.Object%29">Android 4.0.1 onPostExecute :

运行doInBackground后在UI线程上。指定的结果是  通过doInBackground返回的值。此方法将不被调用,如果  任务被取消。

所以,如果你还在针对Android的2台设备,你应该假设onPostExecute将被调用,在onPostExecute检查空的结果。

So if you are still targeting Android 2 devices you should assume that onPostExecute will be called and in onPostExecute check for null result.

这篇关于onPostExecute上取消的AsyncTask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 18:24