Android: CursorLoader, LoaderManager, SQLite

Trying to update my old application in which some methods are deprecated. I found out that if I want to work with a ListView that shows data from db, I have to use LoaderManager + CursorLoader. CursorLoader works with content providers. So, for each table in my db, should I create a content provider now? Why should I? As far as I know, content providers are used to exchange some information with other applications, but my application does not provide any information. Can I use CursorLoader without content providers?

+29
java android multithreading android-loadermanager
Jun 13 2018-12-12T00:
source share
2 answers

I wrote a blog post on this subject. You can also check this answer for more information. Hope this reveals everything for you.

As Barak mentioned, you can implement CursorLoader without content providers by extending the AsyncTaskLoader<Cursor> class. However, most tutorials and sample code use ContentProvider s, and the Android team seems to be encouraging its use. It is also much more complicated than implementing your own class.

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

+22
Jun 13 2018-12-12T00:
source share

Yes, you can, you can have custom data downloaders that can load objects that you define, or any type or list of objects.

Just browse the samples from the android sdk file for LoaderCustomSupport.java in the samples and demo compatibility files.

0
Jun 13 2018-12-12T00:
source share



All Articles