ListAdapter生命周期和屏幕旋转为取消的AsyncTask [英] ListAdapter lifecycle and screen rotation for canceling a AsyncTask

查看:241
本文介绍了ListAdapter生命周期和屏幕旋转为取消的AsyncTask的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有当视图通过onDestoryView毁灭,我取消AsyncTask的()。这个问题是我做的downloader.cancel(真);它不会取消。事实上,它会返回false。目前,它引用了ListAdapter将项目添加到它。然而,当我打开屏幕景观,ListAdapter是onPostExecute期间空。我想不通的时候ListAdapter变为零。我曾经尝试都onDestory和onDestoryView取消的AsyncTask的ListAdapter成为空之前,但它永远不会奏效。这是一个ListFragment BTW内。

I have a asynctask that I cancel when the view is destoried via onDestoryView(). This problem is I do "downloader.cancel(true);" and it wont cancel. In fact, it will return false. Currently, it references the ListAdapter to add items to it. However when I turn the screen to landscape, the ListAdapter is null during the onPostExecute. I cannot figure out when the ListAdapter becomes null. I have tried both onDestory and onDestoryView to cancel the asynctask before the ListAdapter becomes null but it never works. This is inside of a ListFragment btw.

有关目前,我只检查是否适配器是AsyncTask的空,但是这确实我的研磨齿轮。我宁愿只取消该任务之前,ListAdapter为null。

For the time being, I just check if the adapter is null in the asynctask but this really grinds my gears. I would rather just cancel the task before the ListAdapter is null.

有谁知道什么时候ListAdapter屏幕中循环是空的ListFragment?

Does anyone know when the ListAdapter is null for a ListFragment during screen rotations?

推荐答案

取消一个AsyncTask的确实的的杀线程。你会在文档中看到线程,像<$ C $方法C>停止和摧毁未实现。所以一旦<一个href=\"http://developer.android.com/reference/android/os/AsyncTask.html#doInBackground%28Params...%29\"相对=nofollow> doInBackground 方法开始执行时,它会运行到完成任务就算用的取消(真)。您将需要code将其恰如其分。

Cancelling an AsyncTask does not kill the Thread. You will see in the docs for Thread that methods like stop and destroy are unimplemented. So once the doInBackground method starts executing, it will run to completion even if the task is cancelled with cancel(true). You will need to code it appropriately.

这篇关于ListAdapter生命周期和屏幕旋转为取消的AsyncTask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆