gpt4 book ai didi

android - cursor.setNotificationUri() 和 getContentResolver().notifyChange(uri,null) 之间的区别

转载 作者:太空宇宙 更新时间:2023-11-03 11:34:21 24 4
gpt4 key购买 nike

我是 android 的新手,谁能告诉我 cursor.setNotificationUri()getContentResolver().notifyChange(uri,null) 在实现时有什么区别内容提供商。

我已经看到 cursor.setNotificationUri()query() 方法中使用,同时更新或插入 getContentResolver().notifyChange()被使用。

我不太了解 getContentResolver().notifyChange() 通知解析器某些数据已更改,但 cursor.setNotificationUri() 做了什么?

最佳答案

它们是共生的。如果您正在实现 ContentProvider,基本上当有人查询您的提供者时,您会生成一个 Cursor 并使用一些合理的 setNotificationUri() 对其调用 code>Uri(例如用于进行查询的 Uri)。稍后,如果您的 ContentProvider 提供的数据发生变化,例如在插入/更新/删除之后,您调用 getContentResolver().notifyChange(uri, null) 以便当前拥有 Cursor 的任何人(因为他们之前查询过)都会收到通知该数据已更改,他们应该重新查询。如果他们使用的是 CursorLoader,则重新查询会自动发生。

关于android - cursor.setNotificationUri() 和 getContentResolver().notifyChange(uri,null) 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40481035/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com