Search code examples
androidsqliteandroid-contentprovider

Do I need a Content Provider with a Cursor Loader?


I am having trouble working out how to use a CursorLoader.

The problem I am trying to solve is how to display data from my SQLite database in a ListActivity. The list rows use a custom layout so need data from 3 fields (all in the same table).

Along with a number of Stack Overflow question I also read this blog post and came to the decision that I needed to create a content provider for my database.

Having never used Content Providers before I went to the Android help on how to do this.

Point 1 states:

You don't need a provider to use an SQLite database if the use is entirely within your own application.

So now I am stuck, I can't seem to use a CursorLoader without a ContentProvider and I am advised against creating a ContentProvider if it is for use only within my application.

I am currently thinking that maybe the help is out of date or was not thinking of Cursor Loaders when it was written?

So do I need to just continue on and create a ContentProvider anyway or is there another way to do this? Any advice will be helpful!


Solution

  • After researching, I found that a ContentProvider IS needed if you are using the built in CursorLoader.

    As wsanville says, you can roll your own Loader so that it does not need a ContentProvider.