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

2

16

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?

Vulcanite answered 13/7, 2011 at 11:20 Comment(0)
V
12

After testing it, simple answer: yes.

Vulcanite answered 21/7, 2011 at 20:38 Comment(1)
I believe my answer is more accurate. Could you accept it or incorporate it into your own answer please? I have a feeling people often don't look past the accepted answer.Hernia
H
31

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)
Hernia answered 28/1, 2014 at 21:28 Comment(0)
V
12

After testing it, simple answer: yes.

Vulcanite answered 21/7, 2011 at 20:38 Comment(1)
I believe my answer is more accurate. Could you accept it or incorporate it into your own answer please? I have a feeling people often don't look past the accepted answer.Hernia

© 2022 - 2024 — McMap. All rights reserved.