ContentResolver的notifyChange方法是否也通知详细的Uri?

发布于 2024-12-19 20:59:17 字数 284 浏览 3 评论 0原文

在应用数据期间,我将 notifyChangeUri 一起使用。

假设我通知 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南风几经秋 2024-12-26 20:59:17

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 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.


~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文