I watched a course about ContentProvider
on the Internet demonstrating how to define and use a ContentProvider
.
I was confused about using the
getContentResolver () return a ContentResolver instance for your application's package.
Pasting it from developer.android.com
Content providers manage access to a structured set of data. They encapsulate the data, and provide mechanisms for defining data security. Content providers are the standard interface that connects data in one process with code running in another process.
When you want to access data in a content provider, you use the ContentResolver object in your application's Context to communicate with the provider as a client. The ContentResolver object communicates with the provider object, an instance of a class that implements ContentProvider. The provider object receives data requests from clients, performs the requested action, and returns the results.
http://developer.android.com/guide/topics/providers/content-providers.html
It returns Content Resolver.
What is the Content Resolver?
The Content Resolver is the single, global instance in your application that provides access to your (and other applications') content providers. The Content Resolver behaves exactly as its name implies: it accepts requests from clients, and resolves these requests by directing them to the content provider with a distinct authority. To do this, the Content Resolver stores a mapping from authorities to Content Providers. This design is important, as it allows a simple and secure means of accessing other applications' Content Providers.
The Content Resolver includes the CRUD (create, read, update, delete) methods corresponding to the abstract methods (insert, delete, query, update) in the Content Provider class. The Content Resolver does not know the implementation of the Content Providers it is interacting with (nor does it need to know); each method is passed an URI that specifies the Content Provider to interact with.
What is the Content Provider?
Whereas the Content Resolver provides an abstraction from the application's Content Providers, Content Providers provides an abstraction from the underlying data source (i.e. a SQLite database
). They provide mechanisms for defining data security (i.e. by enforcing read/write permissions) and offer a standard interface that connects data in one process with code running in another process.
Content Providers provide an interface for publishing and consuming data, based around a simple URI addressing model using the content:// schema
. They enable you to decouple your application layers from the underlying data layers, making your application data-source agnostic by abstracting the underlying data source.
Source - androiddesignpatterns