Surya KLSV
Surya KLSV

Reputation: 1260

Difference between query() in ContentProvider and ContentResolver classes

I'm new to android. Right now I'm doing Content Providers. I'm following the "Pro android 3" book. From there I have implemented the BookProvider example. I have implemented the insert,update,delete functions in BookProvider class which extends ContentProvider class.But then while using the functions, there I have used:

ContentResolver cr = context.getContentResolver();
cr.delete(uri,contentValues);

My doubt is in what way the methods that I have written in the BookProvider class communicates with the ContentResolver class ...

Also someone please example the basic definitions, difference and relation between Context,ContentProvider and ContentResolver classes

One more doubt is that in some examples they have explicitly casted context objects into Activity objects ... How are Activity and Context classes related?

Upvotes: 1

Views: 1070

Answers (1)

K-ballo
K-ballo

Reputation: 81349

A Context contains information about the context where an Activity, Service or BroadcastReceiver is running. All those classes inherit directly or indirectly from Context. So it stands that all Activityies are Contexts, but only some Contexts are Activityies

When you define a ContentProvider you specify one or more base uris for the elements it can handle. The ContentResolver job is to dispatch your commands to a ContentProvider, based on the uri you provide.

Upvotes: 2

Related Questions