ContentResolver的notifyChange方法是否也通知详细的Uri?
在应用数据期间,我将 notifyChange
与 Uri
一起使用。
假设我通知 content://com.package.my/items
。
我还详细介绍了显示来自 content://com.package.my/items/1
的数据的 Activity
。
通知“常规”Uri
是否也会导致“详细”Uri
被通知?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
notifyChange
方法发送详细 URI 的通知。但是,如果您在
ContentResolver.registerContentObserver(Uri uri, boolean notifyForDescentents, ContentObserverobserver)
处注册一个ContentObserver
,您就可以注册一个要通知的基Uri
如果任何后代Uri
已更改(用于发送更改通知)。我假设您有一个
ContentProvider
,并且您通过ContentResolver
从该ContentProvider
查询Cursor
。如果您在ContentProvider.query()
方法中返回的Cursor
上设置通知 URI,则您的CursorAdapter
将自动更新视图,如果通知 URI 或其任何后代发生更改(请参阅 光标)。如果您使用ContentProvider
更改数据,请务必在ContentProvider
的更新、插入、删除
中发送通知。The method
notifyChange
sends a notification for the detailed URI.But if you register a
ContentObserver
atContentResolver.registerContentObserver(Uri uri, boolean notifyForDescendents, ContentObserver observer)
you can register a baseUri
to be notified if any descendantUri
has been changed (is used to send change notification).I assume you have a
ContentProvider
and that you query aCursor
from thatContentProvider
through aContentResolver
. If you set the notification URI on theCursor
that you return in theContentProvider.query()
method, yourCursorAdapter
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 youContentProvider
be sure to send a notification inupdate,insert,delete
of yourContentProvider
.