Detailed explanation and sample code of Android content provider

Android: use of content provider.

1. Introduction to content provider

2. Use an off the shelf content provider

3. Define your own content provider

1、 Introduction to content provider

We say that the four core components of Android applications are: activity, service, broadcast receiver and content provider. In Android, applications are independent of each other, and they all run in their own independent virtual machines. The content provider provides a method for sharing data between programs. A program can use the content provider to define a URI and provide a unified operation interface. Other programs can access the specified data through this URI for data addition, deletion, modification and query.

2、 Use an off the shelf content provider

Let's take reading the content provider provided by the address book of the Android system as an example to illustrate how to use the ready-made content provider.

1. Create a new project lesson20_ ContentProvider project.

2、res/layout/main. Omitting the XML content is to make a query button.

3、MainContentProvider. The contents of Java are as follows:

At androidmanifest Add in XML:

4. Implementation effect diagram:

The above is a simple example of Android content provider. Continue to supplement relevant knowledge in the future. Thank you for your support!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>