Stack
Stack

Reputation: 1254

Difference between querying with Android Content resolver and Sqlite database connection?

I have a doubt that how Content resolver works, does it uses sqlite database connection implicitly for querying or how does it works and what may be the major difference in using content resolver and sqlite database connection for querying in android?

Upvotes: 1

Views: 276

Answers (2)

Nithish
Nithish

Reputation: 6009

ContentResolver is used to select the specific ContentProvider.

Content Resolver provides an abstraction from the application’s Content Providers, Content Providers provide an abstraction from the underlying data source (i.e. a SQLite database).

ContentResolver --> ContentProvider --> SQLiteDatabase

I found some decent explanation about Content Resolvers & Content Providers here. It's worth a read. Hope this helps in understanding a bit more about Content Resolvers & Content Providers

Upvotes: 2

k3b
k3b

Reputation: 14755

Contentprovider/Contentresolver use a modell similar to sql-dabase:

  • projection: you have colums you are interested in (in sql select col1,col2,....)
  • selection or filter: find/filter rows (in sql WHERE expression)

Contentprovider can be easily implemented with a sqLite database.

But Contentprovider can also be implemented without any database.

  • Example: the media contentprovider (photo, video and audio files) is implemented with a sqLight database
  • Example: the DocumentFile contentprovider for files (in internal memory or on sdcard, on usbstick, in the cloud...) are not implemented through a database but can be queried like any other contentresolver.
  • *

When to use Contentproviders instead of using the raw database?

  • If you want to share data with other apps (example the phonebook-conacts contentprovider)
  • When it is essential that one app keeps control over what other apps can do. Example: Since android-7.0 access to files on sd-card is restricted to make implementing malware more difficuilt. Other apps can use the DocumentFile-provider/resolver

Upvotes: 1

Related Questions