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

问题描述

我为什么要使用 AsyncTaskLoader ,当我应该preFER CursorLoader ,反之亦然?

Why should I use AsyncTaskLoader, and when should I prefer CursorLoader and vice-versa ?

在官方页面,在App-上市的例子显示,这里使用的,而不是CursorLoader AsyncTaskLoader。

In official page, the App-listing example is shown, this uses AsyncTaskLoader instead of CursorLoader.

什么是这两种的优点和缺点?我读的地方有关CursorLoader没有采取有关内容改变护理(SQLite中)。

What are the advantages and disadvantages of these two? I read somewhere about the CursorLoader not taking care about the content change (in sqlite).

请告诉我,如果我的问题不明确。我很高兴地编辑,并在任何时候都需要改变。

Please tell me, if my question is not clear. I am happy to edit and make changes where ever needed.

感谢您!

推荐答案

AsyncTaskLoader是一个抽象的加载器,提供了一个AsyncTask的做work.So你平时延长AsyncTaskLoader创建使用之间你自己定制loader.The关键的区别一个AsyncTask的,并使用一个AsyncTaskloader的配置更改(如方向变化)不会影响AsyncTaskLoader及其过程,因为AsyncTaskLoader都有自己的生命周期;而配置更改影响的AsyncTask不利的,因为它连接到主机活动的整个生命周期。

AsyncTaskLoader is a abstract Loader that provides an AsyncTask to do the work.So you usually extend the AsyncTaskLoader to create your very own custom loader.The key difference between using a AsyncTask and using a AsyncTaskloader is that configuration changes (such as orientation change) do not affect AsyncTaskLoader and its processes since AsyncTaskLoader has its own lifecycle ;while the configuration changes affect the AsyncTask adversely since it is connected to host activity's lifecycle.

CursorLoader是一个加载器查询ContentResolver的,并返回一个Cursor.This类实现以标准方式的装载协议查询cursors.It不过是AsyncTaskLoader。

CursorLoader is a loader that queries the ContentResolver and returns a Cursor.This class implements the Loader protocol in a standard way for querying cursors.It is nothing but a AsyncTaskLoader.

总之,你可以使用AsyncTaskLoader当你通过扩展AsyncTaskLoader&LT创建一个自定义加载器; D>其中D =anything_you_want_to_load。并使用CursorLoader时,你必须实现一个加载器加载光标(通常用于当你从一个数据库加载数据)。

In short,you can use AsyncTaskLoader when you have to create a custom loader by extending AsyncTaskLoader< D > where D="anything_you_want_to_load". And you use CursorLoader when you have to implement a loader which loads Cursor (usually used when you have load data from a database).

这篇关于CursorLoader和AsyncTaskLoader的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 07:38