Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CursorLoader not updating after data change

I have created a small application, trying to understand the functionality of the LoaderManager and CursorLoader-classes.

I have implemented LoaderCallbacks<Cursor> on my FragmentActivity-class and everything works fine, except the fact that when I update my data via ContentResolver.update() or ContentResolver.insert()-methods, onLoadFinished() is not called and as a result my data doesn't update.

I have a custom ContentProvider and I am wondering if the problem is in my ContentProvider not notifying that the data changed or something else.

like image 718
akalipetis Avatar asked Oct 27 '11 11:10

akalipetis


2 Answers

Did you call setNotificationUri(ContentResolver cr, Uri uri) on the Cursor before returning it in ContentProvider.query()?

And did you call getContext().getContentResolver().notifyChange(uri, null) in the 'insert' method of your ContentProvider?

EDIT:

To get a ContentResolver call getContext().getContentResolver() in your ContentProvider.

like image 182
thaussma Avatar answered Nov 03 '22 21:11

thaussma


Also check if you call somewhere cursor.close(), because in this case you unregister the content observer which was registered by CursorLoader. And the cursor closing is managed by CursorLoader.

like image 27
ultraon Avatar answered Nov 03 '22 20:11

ultraon