Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When ContentResolver.notifyChange() is called for a given URI, are ContentObservers observing descendent URIs of this URI notified?

A hopefully straightforward question: When ContentResolver.notifyChange() is called for a given URI, are ContentObservers observing descendent URIs of this URI notified?

E.g. Say I have a cursor setup to observer the URI of a specific resource:

 Uri uriA = Uri.parse("content://" + AUTHORITY + "/orders/21");
 cursor.setNotificationUri(getContext().getContentResolver(), uriA);

I then notify the ContentResolver of a change to an ancestor of this URI (e.g. because I have deleted all orders):

 Uri uriB = Uri.parse("content://" + AUTHORITY + "/orders");
 getContext().getContentResolver().notifyChange(uriB, null);

Would my Cursor, registered to observe uriA, be notified?

like image 525
tomtheguvnor Avatar asked Jul 13 '11 11:07

tomtheguvnor


People also ask

What does ContentResolver query () return?

The ContentResolver. query() client method always returns a Cursor containing the columns specified by the query's projection for the rows that match the query's selection criteria. A Cursor object provides random read access to the rows and columns it contains.

What is the use of ContentResolver in Android?

The Content Resolver behaves exactly as its name implies: it accepts requests from clients, and resolves these requests by directing them to the content provider with a distinct authority. To do this, the Content Resolver stores a mapping from authorities to Content Providers.

What is a URI in Android?

A URI is a uniform resource identifier while a URL is a uniform resource locator.

How do I use content observer?

To use the ContentObserver you have to take two steps: Implement a subclass of ContentObserver. Register your content observer to listen for changes.


1 Answers

It depends on how it was registered. If the ContentObserver was registered with the notifyForDescendents argument set as true, then yes. Otherwise no.

The registration is done through the method ContentResolver#registerContentObserver:

void registerContentObserver (Uri uri, boolean notifyForDescendents, ContentObserver observer)
like image 102
Xiao Avatar answered Sep 20 '22 10:09

Xiao