Implementation and simple example code of Android ContentProvider

1、 Concept and description

ContentProvider definition:

Content provider is the basic module of an Android application. It provides content to the application. They encapsulate data and provide it to the application. Through this contentresolver interface, the ContentProvider can be used to share data between different applications. Android provides ContentProvider (video and audio) for some common data, The ContentProvider organizes data in the form of tables.

Uri definition:

Each content provider has a public URI, which is used to represent the data provided by the content provider. All content providers provided by Android are stored in android.provider.

2、 Process of implementing ContentProvider

1。 The constants required to define the ContentProvider (the most important thing is to define the content_uri. The content_uri is of URI type. In fact, it is obtained through string parsing)

2。 Define a class that inherits ContentProvider

3。 Implement the query, insert, update, delete, GetType and oncreate methods

(1) . define urimatcher

(2) . override GetType method

(3) . create userprojectmap hash map static object

(4) . override the insert method

(5) . rewrite the query method

4。 Declared in androidmanifest.xml

Thank you for reading, hope to help you, thank you for your support to this site!

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
分享
二维码
< <上一篇
下一篇>>