Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android cursor.setNotificationUri()和getContentResolver()之间的差异。notifyChange(uri,null)_Android_Android Contentprovider_Android Cursor - Fatal编程技术网

Android cursor.setNotificationUri()和getContentResolver()之间的差异。notifyChange(uri,null)

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()通知解析器某些数据

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

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


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

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

我注意到一件事的可能重复,如果您在
query()
方法中不使用
setNotificationUri()
和在update/delete/insert方法中不使用
notifyChange()
,您的内容提供程序仍然可以工作。