What is cursor.setNotificationUri() used for?

后端 未结 3 1877
太阳男子
太阳男子 2020-12-05 00:18

I did research on how to use ContentProviders and Loaders from this tutorial

How I see it: We have an Activity with ListView,

3条回答
  •  天命终不由人
    2020-12-05 00:58

    If you call Cursor.setNotificationUri(), Cursor will know what ContentProvider Uri it was created for.

    CursorLoader registers its own ForceLoadContentObserver (which extends ContentObserver) with the Context's ContentResolver for the URI you specified when calling setNotificationUri.

    So once that ContentResolver knows that URI's content has been changed [ this happens when you call getContext().getContentResolver().notifyChange(uri, contentObserver); inside ContentProvider's insert(), update() and delete() methods ] it notifies all the observers including CursorLoader's ForceLoadContentObserver.

    ForceLoadContentObserver then marks Loader's mContentChanged as true

提交回复
热议问题