AsyncTaskLoader VS的AsyncTask [英] AsyncTaskLoader vs AsyncTask
问题描述
由于蜂窝
和 V4兼容库
也可以使用 AsyncTaskLoader
。据我了解,在 AsyncTaskLoader
可通过配置的变化求生存像屏幕翻转。
Since Honeycomb
and the v4 Compatibility Library
it is possible to use AsyncTaskLoader
. From what I understand, the AsyncTaskLoader
can survive through config changes like screen flips.
时,则建议使用 AsyncTaskLoader
而不是的AsyncTask
?请问 LoaderManager
得到的图片吗?
Is it recommended to use AsyncTaskLoader
instead of AsyncTask
? Does LoaderManager
get in the picture too?
但我没有找到任何很好的例子(S)如何正确使用 AsyncTaskLoader
。该文档还提供没有例子。任何人都可以提供一些很好的例子。
But I haven't found any good example(s) about how to correctly use the AsyncTaskLoader
. The docs also provide no examples. Can anyone provide some good examples.
推荐答案
您可以看看兼容性库的源$ C $ C以获得更多信息。什么是 FragmentActivity
所做的是:
You can have a look at the compatibility library's source code to get more info. What a FragmentActivity
does is:
- 让
LoaderManager
列表的 - 确保它们不会当你翻转手机(或其他配置发生变化)时通过使用节能实例销毁
onRetainNonConfigurationInstance()
- 踢右装载程序,当你调用
initLoader()
在活动
- keep a list of
LoaderManager
's - make sure they don't get destroyed when you flip your phone (or another configuration change occurs) by saving instances using
onRetainNonConfigurationInstance()
- kick the right loader when you call
initLoader()
in your Activity
您需要使用 LoaderManager
的装载机接口,并提供必要的回调创建您的装载机(S)和填充它们返回的数据您的意见。
You need to use the LoaderManager
to interface with the loaders, and provide the needed callbacks to create your loader(s) and populate your views with the data they return.
一般应该比管理的AsyncTask
的自己更容易。然而, AsyncTaskLoader
是不完全有据可查的,所以你应该学习的例子中的文档和/或之后 CursorLoader 型号的code code>。
Generally it should be easier than managing AsyncTask
's yourself. However, AsyncTaskLoader
is not exactly well documented, so you should study the example in the docs and/or model your code after CursorLoader
.
这篇关于AsyncTaskLoader VS的AsyncTask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!