Having fragment like below, in normal flow the onCreateLoader and onLoadFinished is called in pair. But when the datasource (the database) content is changed, and since the loader is monitoring the data change the loader will issue another call to onLoadFinished() with new data filled in cursor. But In my case it does not want to change the current cursor in use, so don't want the loader deliver the updated cursor vis another onLoadFinished call, or disable the loader's monitoring part.
Is there a way to do it?
AFragment extends Fragment implements LoaderCallbacks<Cursor> {
protected void startSupportLoaderManager() {
getActivity().getSupportLoaderManager()
.initLoader(LOADER_ID, null, this);
}
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
return createLoader(getActivity(), id, args, null);
}
@Override
public void onLoaderReset(Loader<Cursor> arg0) {
if (mAdapter != null) {
mAdapter.resetCursor();
}
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
...
}
}
EDIT: Kinda of knowing this may work, but feel still missing some dot. Here is what the thought: In the implementation of ContentProvider, for insert(), update(), delete() we do
getContext().getContentResolver().notifyChange(uri, null);
And in the CursorLoader it did cursor.registerContentObserver(mObserver); in
public Cursor loadInBackground() {
Cursor cursor = getContext().getContentResolver().query(mUri, mProjection, mSelection,
mSelectionArgs, mSortOrder);
if (cursor != null) {
// Ensure the cursor window is filled
cursor.getCount();
cursor.registerContentObserver(mObserver);
}
return cursor;
}
So it in some way is monitoring the Uri data source change, same as we do on cursor cursor.setNotificationUri(getContext().getContentResolver(), uri);
So if we could provide a Uri, which could used for insert/update/delete, but is different than the Uri we give to the Loader, that would still do the inert/update/delet operation but the loader will not be notified because of the Uri is different. So basically, the loader will use different Uri than the Uri the other data operation using.
Not sure If understanding how the Loader's monitoring with the content Uri is correct. Maybe there is better way of doing it? Any suggestion is appreciated.