Android Content Provider details 6

Source: Internet
Author: User

Create a Content Provider

The content provider Manages access to the central data warehouse. You implement a provider that implements one or more classes in an Android application, and adds some elements in the manifest file. You implement a subclass of ContentProvider, which serves as the interface between your provider and other applications. Although content providers aims to provide data to other applications, you can also create an activity in your own application to allow users to query and modify the data managed by your provider.

Preparations before creation

Before creating a provider, you need to do the following:
1. Determine whether you need a content provider. To provide one or more of the following features, you need to create a content provider:
You want to provide complex data or files to other applications.
You want to use protection to copy complex data from your application to other applications.
You want to use the search framework to provide Custom Search recommendations.
If it is used inside your application, your provider does not need to use the SQLite database.
2. If you have not made a decision, read the topic Content Provider Basics to learn more about provider.
Next, follow these steps to create your provider:
1. design the original storage method for your data. A content provider provides data in two ways:
File data
Data stored in files, such as video, video, and audio. Store files in the private space of your application. To respond to requests sent from other applications to a file, your provider can provide a handle for the file.
"Structured" Data
Refers to the data, arrays, or small structures stored in the database. Data is stored as tables. A row represents a piece of data, just like a Member or entry in the list. A column represents a part of the data, such as the name of a person or the price of a person. A common method to store these types of data is to use the SQLite database, but you can also use other forms. For more information about the storage methods in the android system, see the design data storage section.
2. Define the ContentProvider class and its methods. This class is the interface between your data and other things in the Android system. For more information about this class, see the section implementing the ContentProvider class.
3. Define the authority string, content URIs, and column name of the provider. If you want the provider's application to process intent, you also need to define the intent action, additional data, and flag. Define the permissions required for applications that want to access your data. You should consider defining these values as contracts into another separate contract class. This class will be displayed to other developers in the future.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.