Development issue/problem:

What is the difference between ContentProvider and ContentResolver? For an SQLite database, I don’t want it. I’m developing a media application.

How can I solve this problem?

Solution 1:

I’ve come up with a statement. In a nutshell.

Content Resolver solves URIs for a specific content provider.

The content provider provides an interface for requesting content.

The way to query the content provider is contentResolverInstance.query(URI,…..).

Solution 2:

ContentProviders are used to abstract other parties’ databases and serve as an interface between your database and the UI/other classes. You need to create your ContentProvider to exchange application data with other applications.

ContentResolver is used to select the right content provider based on ContentUris. ContentUri can look like this

Contents: //com.android.contacts/contacts/3

  • content:// is called a schema and indicates that it is a ContentUri.
  • com.android.contacts is called a content authority, and ContentResolver uses it to resolve a dispute with a single provider (in this case, ContactProvider).
  • Pins is a path that identifies a subset of the supplier data (e.g. the name of the table).
  • 3 is an identifier used to uniquely identify a string in a subset of data.

Give here a description of the image

NOTE : Your own application can also use this method to process the data.

For more information, see Android Content Providers.

Solution 3:

Two-level abstraction:

ContentResolver -> ContentProvider ->SQLiteDatabase

The main difference is that, as mentioned in other responses.
A ContentProvider makes the private data of your application available to an external
application, and
ContentResolver returns the correct ContentProvider to all ContentProviders that use the URI.

In-depth understanding (two-step abstraction)

Let’s take a detour.
We all know that when you create an SQLite database, it remains private for your application, which means that you cannot share your application data with another external application.

How is the data exchanged?

ContentProvider and ContentResolver are part of the android.content package. These two classes work together to provide a reliable and secure data exchange model between applications.
ContentProvider makes data stored in an SQLite database accessible to other applications without telling them what the underlying implementation of your database is.
It therefore extracts the SQlite Database. But wait, there’s a trap! !!
An external application does not have direct access to the content provider. To do this, you must first interact with another class called ContentResolver
Think ContentResolver as a ContentProvider finder. There is only one instance, and all content providers on your device are registered using a simple URI namespace. If you want to contact a specific content provider, all you need to know is their URI. Pass it on to the ContentResolver and it will find the provider based on the URI.
Now let’s look at the main method, getContentResolver().query(URI,String[] proje…..).

What happens when getContentResolver().query(URI,String[] proj…..) is called

The query() method belongs to the ContentResolver class, but calls the abstract query() method of the solved ContentProvider and returns a cursor object.
This gives the external application access to the private database via two abstract layers.

Just to add more than
points: You cannot create your own ContentResolver class, but you can always create your own
-ContentProvider class.

I hope you have a better understanding of
. You can see an example code to create SQLitedatabase, ContentProvider etc. here, but it is not very well documented.

Solution 4:

by 2020

Content Resolver : To retrieve data

Content provider : To respond to the data

Good luck!

what is contentresolver in android,what is content provider in android,contentresolver query example,content provider in android pdf,custom content provider example in android,sharing data between applications with content providers in android,content provider in android example,what is the use of content provider in android mcq,content provider in android example androidhive