Android content providers-create content providers (Overview)

Source: Internet
Author: User

The content provider Manages access to the core data resource library. You can use the provisioner as an android application together with the configuration file.ProgramOne or more classes. One of the classes you want to implement is the contentprovider subclass. This class is the interface between the provider and other applications. Although the content provider means that data is valid for other applications, you can also have an activity in your application that allows users to query and modify data managed by the provider.

Preparations before creating a content provider

Before creating a provisioner, do the following:

1. Determine whether a content provider is required. If you want to provide one or more of the following features, you need to create a content provider:

A. You want to provide complex data or files to other applications;

B. You want to allow users to copy complex data from your application to other applications;

C. You want to use the search framework to provide customized search solutions.

If you only use an SQLite database in your own application, you do not need a provisioner.

2. Read the topic "content providers' basics" carefully to learn more about providers' knowledge.

Next, follow these steps to create the provisioner:

1. Design row-based storage for data. The content provider provides data in two ways:

File data:

Usually, the data put into the file includes photos, audio, or video. These files are stored in the private space of your application. In the request response to a file from another application, your provider can process the file.

Structured Data:

Data is usually stored in databases, arrays, or similar structures, and stored in a format compatible with the table (row and column structures. A row represents an object, such as an individual or an item in the list. A column represents certain data of a row object, such as a person's name or the price of a project. The common method to store this type of data is to save it in an SQLite database, but you can use any other persistent storage type. For effective storage types in the Android system, see "design data storage.

2. Define the implementation class of a specific contentprovider class and the method required by this class. This class is the interface between your data and other parts of the Android system. For more information about the contentprovider class, see the section "Implementing the contentprovider class.

3. Define the authorization string, content resource identifier (URI), and column name of the provider. If you want the provider to process intent objects, you also need to define intent actions, additional data, and identifiers. At the same time, you need to define necessary access permissions for applications that want to access your data. You should define all these values as constants in an independent contract class so that this class can be exposed to other applications in the future. For more information about content resource identifier (URI), see "design content resource identifier (URI )". For more information about intent objects, see "intent and data access ".

4. Add other options, such as sample data or the implementation of abstractthreadedsyncadapter that can synchronize data between providers or cloud-based data.

Related Article

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.