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

问题描述 投票:3回答:1

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

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

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

android android-contentprovider android-cursor
1个回答
14
投票

它们被共生使用。如果要实现ContentProvider,本质上是当有人查询您的提供程序时,您会产生Cursor并使用一些有理的setNotificationUri()(例如用于进行查询的Uri)在其上调用Uri。稍后,如果ContentProvider提供的数据发生更改,例如在插入/更新/删除之后,您可以调用getContentResolver().notifyChange(uri, null),以便当前拥有Cursor(因为他们已被更早查询)的任何人都收到有关数据已更改的通知,并应重新查询。如果他们使用的是CursorLoader,则会自动进行重新查询。

© www.soinside.com 2019 - 2024. All rights reserved.