正在使用的AsyncTask仍然建议在后台加载ListView的项目? [英] Is using AsyncTask still recommended for loading listView items in the background?
问题描述
我听说有装载数据的一些新的解决方案中的背景,更推荐比AsyncTask的(像的装载机的)。
I've heard that there are some new solutions for loading data in the background which are more recommended than AsyncTask (like loaders).
AsyncTasks是巨大的,易于使用。然而,它有一定的局限性:
AsyncTasks are great and easy to use. However, it has some limitations:
-
类本身必须被修改,因为它是由尚未完成的任务(约256左右)的数量的限制。当然,在一个列表视图的适配器,我总是如果它没有必要取消任务(例如,当我需要更新用于不同的项目,一个视图)。
The class itself has to be modified since it's limited by the number of pending tasks (about 256 or so). Of course, in a listView's adapter, I always cancel a task if it's not needed(for example when I need to update a view that was used for a different item).
我也不得不取消他们全部(或以不同的方式处理)正在重新创建的活动/片段时。
I also have to cancel them all (or handle in a different way) when the activity/fragment is being re-created.
由于1安培的; 2,我需要管理他们,有一个参考个个
Because of 1&2, I need to manage them and have a reference to all of them
AsyncTask的使用任务队列,有时我需要使用堆栈来代替,所以我不得不创建我自己的类的AsyncTask的使用堆栈来代替。
AsyncTask uses a queue of tasks, and sometimes I need to use a stack instead, so I had to create my own class of AsyncTask that uses a stack instead.
是否有AsyncTask的替代品?
The question
Are there alternatives for AsyncTask?
我知道这是问一些职位之前(如这里) ,但我在想,如果有数据加载中取代了AsyncTask的背景一个新的通用方式。
I know this was asked in some posts before (like here), but I was thinking if there is a new general way to load data in the background which replaces the asyncTask.
关于装载机,我认为这个想法是,它们用于数据库和contentProviders,但它们也可用于从互联网加载(例如)数据(如图像文件)?
About Loaders, I think the idea is that they are used for databases and contentProviders, but can they also be used for loading (for example) data from the Internet (like images files) ?
还有由谷歌(此处 ,被称为bitmapFun)做了一个很好的样本,而根据我所看到的使用AsyncTask的(甚至延长也许是因为我mentionsed由于同样的原因吧,)。但是,也许我错过了什么事吗?
There is also a nice sample made by google (here, called "bitmapFun"), which according to what I see uses AsyncTask (and even extend it, maybe because of the same reasons I've mentionsed) . But maybe I'm missing there something too?
推荐答案
是的。
装载机进行管理AsyncTasks。如果您使用的不是装载机,你可能缺少管理,它们需要。
Loaders are managed AsyncTasks. If you are not using a Loader, you are probably missing the management that they require.
AsyncTasks(和装载机)是pretty的糟糕的方式得到的东西是关闭设备。以获得从远程服务器外观数据到使用IntentService。请参阅: https://www.youtube.com/watch?v=xHXn3Kg2IQE
AsyncTasks (and Loaders) are a pretty bad way to get stuff that is off the device. To get data from a remote server look into using an IntentService. See: https://www.youtube.com/watch?v=xHXn3Kg2IQE
这篇关于正在使用的AsyncTask仍然建议在后台加载ListView的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!