Content Providers and Content Resolvers are a common source of
confusion for beginning Android developers. Further, online tutorials and
sample code are not sufficient in describing how the two classes work together
to provide access to the Android data model. See Android training for concepts related to android and its
applications.
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.
Content provider: Whereas the 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). 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.
A content provider component supplies data from one application to
others on request. Such requests are handled by the methods of the
ContentResolver class. A content provider can use different ways to store its
data and the data can be stored in a database, in files, or even over a
network.
Content providers let you centralize content in one place and have
many different applications access it as needed. A content provider behaves
very much like a database where you can query it, edit its content, as well as
add or delete content using insert(), update(), delete(), and query() methods.
In most cases this data is stored in a SQlite
database.
A content provider is implemented as a subclass of ContentProvider class and must
implement a standard set of APIs that enable other applications to perform
transactions.
Content providers can help an application manage access to data
stored by itself, stored by other apps, and provide a way to share data with
other apps. 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. Implementing a content
provider has many advantages. Most importantly you can configure a content
provider to allow other applications to securely access and modify your app
data as illustrated in figure.
Use content providers if you plan to share data. If you don’t plan to
share data, you may still use them because they provide a nice abstraction, but
you don’t have to. This abstraction allows you to make modifications to your
application data storage implementation without affecting other existing
applications that rely on access to your data. In this scenario only your
content provider is affected and not the applications that access it. For
example, you might swap out a SQLite database for alternative storage as
illustrated in figure 2. (Learn more database concepts from SQL server training).
If you are making use of any of these classes you also need to
implement a content provider in your application. Note that when working with
the sync adapter framework you can also create a stub content provider as an
alternative. We need content provider in the following cases:
- You want to implement custom search suggestions in your application
- You need to use a content provider to expose your application data to widgets
- You want to copy and paste complex data or files from your application to other applications
Content providers offer granular control over the permissions for
accessing data. You can choose to restrict access to a content provider from
solely within your application, grant blanket permission to access data from
other applications, or configure different permissions for reading and writing
data.
You can use a content provider to abstract away the details for
accessing different data sources in your application. For example, your application
might store structured records in a SQLite database, as well as video and audio
files. You can use a content provider to access all of this data, if you
implement this development pattern in your application.
Learn
Android
Want to excel in android and develop Android Apps, it is the
foundation of our advanced Android curriculum. Online course by Learn IT
Training blends you theoretically and practically to build great apps the right
way. We take you through the basics and moves on to advanced concepts in
Android app development providing online classes with highly qualified professional trainers and will
assist while attending the interviews
even after completion of course.
Want to take a free demo to register go through link:
For more details visit:
Visit:
www.learnittraining.com
Email: contact@learnittraining.com
Phone: INDIA +91 9912989639, USA +12108585008




Comments
Post a Comment