【问题标题】:Difference between cursor.setNotificationUri() and getContentResolver().notifyChange(uri,null)cursor.setNotificationUri() 和 getContentResolver().notifyChange(uri,null) 之间的区别
【发布时间】:2016-11-08 07:15:38
【问题描述】:

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

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

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

【问题讨论】:

标签: android android-contentprovider android-cursor


【解决方案1】:

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

【讨论】:

  • 我注意到一件事,如果你在query() 方法中不使用setNotificationUri(),在更新/删除/插入方法中不使用notifyChange(),你的内容提供器仍然可以正常工作。跨度>
猜你喜欢
  • 2015-05-10
  • 1970-01-01
  • 1970-01-01
  • 2013-01-12
  • 2011-05-10
  • 2023-03-08
  • 2014-12-04
  • 1970-01-01
相关资源
最近更新 更多