Does ContentResolver notifyChange method notifies also detail Uri's?

房东的猫 提交于 2019-12-07 00:37:21

问题


During applying data I use notifyChange with an Uri.

Let's say I notify content://com.package.my/items.

I have also detail Activity that displays data from content://com.package.my/items/1.

Does notifying 'general' Uri results also in 'detail' Uri being notified?


回答1:


The method notifyChange sends a notification for the detailed URI. But if you register a ContentObserver at ContentResolver.registerContentObserver(Uri uri, boolean notifyForDescendents, ContentObserver observer) you can register a base Uri to be notified if any descendant Uri has been changed (is used to send change notification).

I assume you have a ContentProvider and that you query a Cursor from that ContentProvider through a ContentResolver. If you set the notification URI on the Cursor that you return in the ContentProvider.query() method, your CursorAdapter will automatically update the view if the notification URI or any of its descendants change (see source of Cursor). If you change the data with you ContentProvider be sure to send a notification in update,insert,delete of your ContentProvider.




来源:https://stackoverflow.com/questions/8397182/does-contentresolver-notifychange-method-notifies-also-detail-uris

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!