如果我在某个地方错了,请纠正我。
ContentProvider
在方法中调用类似这样的东西query(…)
:
// Tell the cursor what uri to watch, so it knows when its source data changes
cursor.setNotificationUri(getContext().getContentResolver(), uri);
CursorLoader
取回光标并注册一个观察者。
/* Runs on a worker thread */
@Override
public Cursor loadInBackground() {
Cursor cursor = getContext().getContentResolver().query(mUri, mProjection,
mSelection, mSelectionArgs, mSortOrder);
if (cursor != null) {
// Ensure the cursor window is filled
cursor.getCount();
registerContentObserver(cursor, mObserver);
}
return cursor;
}
/**
* Registers an observer to get notifications from the content provider
* when the cursor needs to be refreshed.
*/
void registerContentObserver(Cursor cursor, ContentObserver observer) {
cursor.registerContentObserver(mObserver);
}
当有人修改数据时,ContentProvider
通知ContentResolver
更改:
getContext().getContentResolver().notifyChange(uri, null);
ContentResolver
反过来通知所有注册的观察者。
由 注册的观察者CursorLoader
强制它加载新数据。