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 ???
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 ContentProvider
s, 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.