Android

Type of Android Component: ContentProvider
Previous Home Next

Data is available to all application. ContentProvider usually the backend is SQLite. They are loosely linked to clients

ContentProvider are object that can

  • retrieve data
  • store data

 

You can think of content providers as a database server. A content provider's job is to manage access to persisted data, such as a SQLite database. there's no common storage area that all Android packages can access.

If your application is very simple, you might not necessarily create a content provider. If you're building a larger application, or one that makes data available to multiple activities or applications, a content provider is the means of accessing your data.A content provider is implemented as a subclass of ContentProvider. We can modify the data with the help of ContentProvider.

public abstract class ContentProvider extends Object implements ComponentCallbacks

Note : Content providers are also useful for reading and writing data that is private to your application and not shared. if you want to share data. You have two options:

  1. You can create your own content provider and extends the ContentProvider class
  2. You can add the data to an existing provider and gives permission to write to it.

Creating a Content Provider :

Firstly, you will set up a system for storing the data. You can store your data any way you want in SQLite database . SQLiteOpenHelper class is helpful for creation of a database and SQLiteDatabase to manage it.

This class extend the ContentProvider class to provide access to the data and must be declare in AndroidManifest.xml.

Content providers encapsulate data and provide it to applications through the single ContentResolver interface. The client use indirectly the ContentResolver object.You get a ContentResolver by calling getContentResolver() from within the implementation of an Activity or other application component.

The system inspects the authority of the given URI when a request is made via a ContentResolver and after that passing the request to the content provider registered with the authority. The UriMatcher class is very useful class for parsing URIs.

Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: