Android cursor.setNotificationUri()和getContentResolver()之间的差异。notifyChange(uri,null)
我是android新手,有谁能告诉我在实现内容提供者时,Android cursor.setNotificationUri()和getContentResolver()之间的差异。notifyChange(uri,null),android,android-contentprovider,android-cursor,Android,Android Contentprovider,Android Cursor,我是android新手,有谁能告诉我在实现内容提供者时,cursor.setNotificationUri()和getContentResolver().notifyChange(uri,null)之间有什么区别吗 我已经看到cursor.setNotificationUri()在query()方法中使用,并且在更新或插入getContentResolver()时使用。notifyChange() 我不太了解getContentResolver().notifyChange()通知解析器某些数据
cursor.setNotificationUri()
和getContentResolver().notifyChange(uri,null)
之间有什么区别吗
我已经看到cursor.setNotificationUri()
在query()
方法中使用,并且在更新或插入getContentResolver()时使用。notifyChange()
我不太了解
getContentResolver().notifyChange()
通知解析器某些数据已更改,但是cursor.setNotificationUri()
在那里做什么?它们是共生使用的。如果您正在实现一个ContentProvider
,基本上当有人查询您的提供者时,您会生成一个游标
,并使用一些rationalUri
(例如用于进行查询的Uri
)在其上调用setNotificationUri()
)。稍后,如果您的ContentProvider
提供的数据发生更改,例如,在插入/更新/删除之后,您可以调用getContentResolver().notifyChange(uri,null)
,以便当前拥有光标的任何人(因为他们之前查询过)都会收到数据已更改的通知,他们应该重新查询。如果他们使用的是CursorLoader
,则会自动进行重新查询。我注意到一件事的可能重复,如果您在query()
方法中不使用setNotificationUri()
和在update/delete/insert方法中不使用notifyChange()
,您的内容提供程序仍然可以工作。