Android contentobserver monitors changes in contact data
1. ContentProvider is a content provider
Contentresolver is the content resolver (operating on the data provided by the content)
Contentobserver is a content observer (observing changes in data provided by content providers)
2. Contentobserver needs contentresolver to register.
resolver.registerContentObserver(uri,true,observer);
① Uri (first parameter): the URI of the ContentProvider that this listener listens on
② Notifyfordescendants (second parameter): set to true. (if the requested URI is content: / / ABC, the URI is content: / / ABC / XYZ, and any data change will be detected.
③ Observer: listener instance.
3. Using the onchange method in observer, when the data changes, the callback method is automatically executed.
① define observer listener
② get the contact contentresolver
③ register observer.
④ important point: add access rights (also dynamic)
⑤ log off observer
[prompt]: here, the observer is written in the form of an internal class. There is only this part of the code, and there is no need to add others.
① contentobserver can timely detect the data changes provided by ContentProvider.
② contentobserver can communicate between programs not only provided by the system, but also created by itself through contentobserver and contentresolver