【发布时间】:2013-01-03 12:38:53
【问题描述】:
我正在使用AsyncTask 来下载我的活动中的图像
流程是这样的:
protected void onPreExecute() {
\\begin animation
}
protected IUpiResponse doInBackground(String... params) {
\\ download the image
}
protected void onPostExecute(IUpiResponse upiResponse) {
\\stop the animation
}
到这里一切都很好,如果我在异步任务工作时进入后台,问题就开始了 有时我在动画停止时得到一个异常空指针,因为视图不再有效(我猜),
如果活动在前台,我可以在停止动画之前检查,但我更愿意避免这种方法,我还能做什么?
【问题讨论】:
-
你试过用
try {} catch{}surrund 吗? -
我同意我可以捕捉到这个异常,但我更愿意避免这种伎俩
-
当您进入 onPostExecute() 时,您是否正在切换到另一个活动??
-
在这种情况下,捕获异常并打印它,以便您知道问题所在,在那里您可以看到您可以做什么。
-
在停止动画之前测试视图是否仍然可见对我来说听起来非常合理
标签: android android-activity android-asynctask activity-lifecycle