android - 禁用 ContentProvider URI 上的通知

标签 android android-contentprovider android-sqlite

我正在寻找一种方法来暂停给定 ContentProviderUri 的通知。用例是:

  1. Activity 通过 CursorLoader 绑定(bind)到 CursorAdapter
  2. Service 可能会在 ContentProvider 上进行大量批量单行更新。
  3. CursorLoader 将在每次行更新时重新加载其内容,因为 ContentProvider 通过 ContentResolver#notifyChange 通知监听器.

由于我无法编辑 ContentProvider,而且我无法控制批处理查询的执行,有没有办法暂停 Uri 上的通知(在执行 Service),直到所有 ContentProvider 管理的查询都已执行?我需要这个以避免因 CursorLoader 的连续重新查询而引起的闪烁。

最佳答案

您不能在您的服务中禁用此机制。但是您应该尝试使用 ContentProviderOperations 对它们进行批处理.

我写了一个introductory post about ContentProviderOperations和另外两个涵盖方法的帖子 withYieldAllowed()withBackReference()分别。

对于您在此处描述的内容,尤其是后者应该引起您的兴趣。

使用 ContentProviderOperations,您可以批处理多个更新和插入。如果您随后调用 applyBatch()在您的 ContentResolver 对象上,ContentProvider 会同时执行它们。

现在我从未使用过 Nicolas Klein 的生成器,但由于他是一位非常非常精通 Android 的开发人员并且在 Google 工作,我敢打赌生成的代码使用事务调用 notifyChange() 最后对整个批处理仅执行一次。

正是您所需要的。

关于android - 禁用 ContentProvider URI 上的通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15872621/

相关文章:

java - Cling 库不定期触发 M 搜索请求

Android Crosswalk Lite - Android Studio 集成

Android Horizo​​ntalScrollView 逐页滚动

android - ContentProvider 用法

android - 如何从 MediaStore 获取音乐的 URI?

android - 如何查询带排序的Android DownloadManager?

android - 如何在 OrmLite 中获取列/字段名称?

android - Sqlite根据where子句android更新一列

android - 如何防止在 Gmail 的集成迷你浏览器中打开链接

android - (Android) 在内部存储中查找路径/Android