开发者

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 ha开发者_JAVA技巧ve 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?


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)


After testing it, simple answer: yes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜