Android ContentProvider Understanding

Source: Internet
Author: User

Content providers are used to save and retrieve data so that data can be shared between different applications in the Android system. Provide data in the form of a URI.

First use a class to inherit the Android.content package under Contentprovide, rewrite the method.

1.public Boolean oncreare () is called when Contentprovide is created.

2. the public int delete (URI Uri, String selection, string[] selectionargs) deletes the specified data.

3. Public URI insert (URI uri, contentvalues values) inserts data

4. public int update (URI uri, contentvalues values, String selection, string[] selectionargs) updates the data under the specified conditions

5. Public Cursor query (URI uri, string[] projection, string selection, string[] Selectionargs, string sortOrder) queries the data for the specified condition

6. Public String GetType (URI uri) returns the MIME type of the URI that represents the data

Second write Uri, by Content://authorities/path

  authorities refers to the value of android:authorities registered in the manifest file

Path represents data, dynamic change

Such as:

 Private StaticUrimatcher matcher=NewUrimatcher (Urimatcher.no_match); Private Static Final intInsert=1; Private Static Final intdelete=2; Private Static Final intUpdate=3; Private Static Final intQuery=4; Private Static Final intQueryone=5; Static{Matcher.adduri ("Com.lss.readcontactmassage.PersonDBProvider", "Insert", INSERT); Matcher.adduri ("Com.lss.readcontactmassage.PersonDBProvider", "delete", DELETE); Matcher.adduri ("Com.lss.readcontactmassage.PersonDBProvider", "Update", UPDATE); Matcher.adduri ("Com.lss.readcontactmassage.PersonDBProvider", "Query", QUERY); //#为通配符, all "query/" are returned with the return code of QueryoneMatcher.adduri ("Com.lss.readcontactmassage.PersonDBProvider", "query/#", Queryone); }

public int match (URI uri) returns the code value of the parameter passed in the Adduri method

Android ContentProvider Understanding

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.