Android ContentProvider calls bursts of setNotificationUri() to CursorAdapter when many rows are inserted with a batch operation

后端 未结 3 784
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-08 01:51

I have a custom ContentProvider which manages the access to a SQLite database. To load the content of a database table in a ListFragment, I use the

3条回答
  •  滥情空心
    2021-02-08 02:47

    In a comment to the original answer, Jens directed us towards SQLiteContentProvider in the AOSP. One reason why this isn't (yet?) in the SDK may be that the AOSP seems to contain multiple variations of this code.

    For example com.android.browser.provider.SQLiteContentProvider seems to be a slightly more complete solution, incorporating the "delayed notifications" principle proposed by Phillip Fitzsimmons while keeping the provider thread-safe by using a ThreadLocal for the batch-flag and synchronizing access to the delayed notification set.

    Yet even though access to the set of URI's to be notified of change is synchronized, I can still imagine that race conditions may occur. For example if a long operation posts some notifications, then gets overtaken by a smaller batch operation, which fires the notifications and clears the set before the first operation commits.

    Still, the above version seems to be the best bet as a reference when implementing your own provider.

提交回复
热议问题