我是 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/