Components: 4.Content Providers

Content Providers:

Content providers store and retrieve data and make it accessible to all applications. They're the only way to share data across applications; there's no common storage area that all Android packages can access. 

  • They are used to share data with other applications.
      > the data can be stored in file system or in SQLite, or in any other
manner that makes sense
  • Content provider is the only way to share data between Android applications
  • Content provider uses a standard interface (URI) to fulfill requests for data from other applications/services
     > Example: Content data : content://contacts/people
  • Content provider extends ContentProvider base class and implements a standard set of methods to allow access to a data store
             > Query
             > Delete
             > Update
            > Insert
  •  Applications do not call these methods directly
           >  They use a ContentResolver object and call its methods instead
           > A ContentResolver can talk to any content provider
  •  Content is represented by URI and MIME type

Content URI Summary

Here is a recap of the important parts of a content URI:
Elements of a content URI
  1. Standard prefix indicating that the data is controlled by a content provider. It's never modified.
  2. The authority part of the URI; it identifies the content provider. For third-party applications, this should be a fully-qualified class name (reduced to lowercase) to ensure uniqueness. The authority is declared in the <provider> element's authorities attribute:
    <provider android:name=".TransportationProvider"          android:authorities="com.example.transportationprovider"          . . .  >
  3. The path that the content provider uses to determine what kind of data is being requested. This can be zero or more segments long. If the content provider exposes only one type of data (only trains, for example), it can be absent. If the provider exposes several types, including subtypes, it can be several segments long — for example, "land/bus", "land/train", "sea/ship", and "sea/submarine" to give four possibilities.
  4. The ID of the specific record being requested, if any. This is the _ID value of the requested record. If the request is not limited to a single record, this segment and the trailing slash are omitted:
    content://com.example.transportationprovider/trains

Comments

Popular posts from this blog

Android Objective type Question and Answers

Android Questions and Answers for written exams

Core Java -----Question and Answers