安卓:CursorLoader,LoaderManager,SQLite的CursorLoader、LoaderManager、SQLite

由网友(不爱又何必纠缠)分享简介:尝试更新我的旧的应用程序,其中一些方法去precated。我发现,如果我要工作,ListView控件显示数据从数据库中,我应该用LoaderManager + CursorLoader。 CursorLoader作品与内容提供商。所以,在我的数据库中每个表我现在应该创建内容提供商?我为什么要 ?据我所知,内容提供商用于...

尝试更新我的旧的应用程序,其中一些方法去precated。我发现,如果我要工作,ListView控件显示数据从数据库中,我应该用LoaderManager + CursorLoader。 CursorLoader作品与内容提供商。所以,在我的数据库中每个表我现在应该创建内容提供商?我为什么要 ?据我所知,内容提供商用于共享与其他应用程序的一些数据库的信息,但我的应用程序不共享任何信息。因此,我可以用CursorLoader没有内容提供商???

Trying to update my old app in which some methods are deprecated. I found out that if I want to work with ListView that shows data from db, I should use LoaderManager + CursorLoader. CursorLoader works with content providers. So for every table in my db I should create content provider now ? Why should I ? As far as I know content providers is used to share some db information with other applications, but my app dont share any information. So can I use CursorLoader without content providers ???

推荐答案

我已经写了blog交 这个问题。您也可以看看这个的答案 以获取更多信息。希望这会清除你的事情了。

I've written a blog post on this subject. You can also check out this answer for more information. Hopefully it will clear things up for you.

正如巴拉克所说,可以通过延长 AsyncTaskLoader&LT实施 CursorLoader 没有内容提供商;光标> 类。也就是说,很多教程和样例code使用的ContentProvider s和它看起来像Android团队鼓励其使用为好。这也是很多比实现自己的类那么复杂。

As Barak mentioned, one can implement a CursorLoader without content providers by extending AsyncTaskLoader<Cursor> class. That said, most of the tutorials and sample code use ContentProviders, and it seems like the Android team encourages its use as well. It's also a lot less complicated than implementing your own class.

这是说,如果你的真正的不想使用内容提供商,戴安娜Hackborn(的Andr​​oid框架开发者之一,也被称为hackbod这里SO)建议编写自己的加载器使用了内容提供商的数据库类,而不是。最简单的方法就是采取 CursorLoader 类从兼容性库的源代码,并更换查询提供查询到自己的数据库辅助类。

That said, if you really don't want to use content providers, Dianne Hackborn (one of the Android framework developers, and also known as "hackbod" here on SO) suggests writing your own loader that uses your database class instead of a content provider. The easiest way is just to take the source of the CursorLoader class from the compatibility library, and replace provider queries with queries to your own db helper class.

阅读全文

相关推荐

最新文章