Difference between contentobserver and datasetobserver

Source: Internet
Author: User

1. contentobserver

Contentobserver monitors specific databases tables through Uris. If the databases table changes, the data in the updated cursor is notified.

If contentprovider is used to operate the database, the query () method of contentprovider uses cursor. seticationicationuri () registers the table described by Uri. getcontext () is called after the insert, delete, and query operations (). getcontentresolver (). notifychange (). After the insert, delete, and query operations are performed on the DB table described by the URI, notifychange () notifies the contentobserver registered by the cursor and calls the onchange method of contentobserver. Generally, the onchange of cursoradapter calls oncontentchanged and calls cursor. requery () in oncontentchanged to update the data in cursor.

Purpose: Notify the user to refresh the data in cursor after there is a change in the database table.

 

2. datasetobserver

Datasetobserver is mainly used to call the methods when the cursor for registration changes, so that users can perform interface refresh and other operations.

First, the cursor registers the datasetobserver through registerdatasetobserver (). When the cursor data changes, for example, when the cursor requery () is called, The onchanged cursor is called to notify the user that the content in the cursor has changed, you can refresh the interface in onchanged. Generally, the notifydatasetchanged notification framework is called in onchanged. When the framework receives a notification, the getview of cursoradapter is called to refresh the interface.

Purpose: Notify the user to refresh the interface when the data in the cursor changes.

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.