SQLiteOpenHelper vs ContentProvider SQLiteOpenHelper vs ContentProvider android android

SQLiteOpenHelper vs ContentProvider


My question is: does the ContentProvider do the same as SQLiteOpenHelper?

ContentProvider is implemented by application's developer if he or she would allow other developers to access to application's database in their application - simply put for sharing. It's like a server of some database and it's client is ContentResolver who knows ContentProvider's authority. For example if you need to get some contacts from your device, than you should use ContentProvider of Contacts database and more concretely it's Contract classes.

If you know an authority of appropriate ContentProvider you may comunicate with it using a ContentResolver object.

In other cases you should interact with database through SQL abstract model which is represented by android.database and android.database.sqlite classes.

And also - ContentProvider available from the primary API level as one of the main component of application.

Update

From the official documentation:

Before you start building a provider, do the following:

Decide if you need a content provider. You need to build a content provider if you want to provide one or more of the following features:

  • You want to offer complex data or files to other applications.
  • You want to allow users to copy complex data from your app into other apps.
  • You want to provide custom search suggestions using the search framework.


  • SQLiteOpenHelper is used to manage database creation and open. It is only a helper class for sqlite database and could be used in anywhere with db operation.

    ContentProvider is one of the 4 basic components of android, the other 3 are Activity, Service and Broadcast. ContentProvider is used to manage access to any structured data set, including sqlite database. The data source of ContentProvider could be a databse but not have to be.

    ContentProvider is often used in providing own data to others applications, just like ContactsProvider and CalendarProvider. And it is more safe to provide some specified interface using ContentProvider, compared with providing a database directly.