Disable notifications on a ContentProvider URI

android, android-contentprovider, android-sqlite

Solution

You cannot disable this mechanism in your Service. But you should try to batch them by using ContentProviderOperations.

I've written an introductory post about ContentProviderOperations and two additional posts covering the methods `withYieldAllowed()` and `withBackReference()` respectively.

Especially the latter one should be of interest for what you've described here.

With ContentProviderOperations you can batch multiple updates and inserts. If you then call `applyBatch()` on your ContentResolver object the ContentProvider executes them all at once.

Now I've never used Nicolas Klein's generator but since he is a very, very proficient Android developer and works at Google, I bet that the generated code makes use of transactions and calls `notifyChange()` only once for the complete batch at the end.

Exactly what you need.

Problem

I'm looking for a way to suspend notifications on a given `ContentProvider`'s `Uri`. The use case is: - An `Activity` is bound to a `CursorAdapter` through a `CursorLoader`. - A `Service` may do a lot of batch, single-row updates on a `ContentProvider`. - The `CursorLoader` will reload its content on every row update, as the `ContentProvider` notifies listeners by `ContentResolver#notifyChange`. Since I cannot edit the `ContentProvider`, and I have no control over the batch queries execution, is there a way to suspend notifications on a `Uri` (in the executing `Service`) until all of the `ContentProvider`-managed queries have been executed? I need this in order to avoid the flickering caused by the continuous requerying of the `CursorLoader`.

Original source