接受的答案有点难以理解,所以我写答案是为了让其他开发人员更容易理解。
- 转到您已扩展的课程
ContentProvider
查找具有以下语法的 query() 方法
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
在返回光标的地方写下这一行
cursor.setNotificationUri(getContext().getContentResolver(), uri);
return cursor;
最后,我的查询方法是这样的
@Nullable
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
Cursor cursor;
cursor = noticeDbHelper.getReadableDatabase().query(
NoticeContract.NoticeTable.TABLE_NAME,
projection,
selection,
selectionArgs,
null,
null,
sortOrder
);
//This line will let CursorLoader know about any data change on "uri" , So that data will be reloaded to CursorLoader
cursor.setNotificationUri(getContext().getContentResolver(), uri);
return cursor;
}`