Android: CursorLoader, LoaderManager, SQLite

旧巷老猫 提交于 2019-11-29 21:23:39
Alex Lockwood

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.

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.

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.

Yes you can, You can have Custom data loaders which can load objects that you define or any object type or list in that matter.

Just look into the samples from the android sdk for the LoaderCustomSupport.java in the compatibility library samples and demos.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!