Reputation: 1192
I have multiple cursor loaders set up pointing to different URIs in my content provider and they work without any issues. Each loader is for a specific table in my database.
However I have now created a new URI in my content provider to execute a join query on my tables. I have created a new loader that points to the URI to be used for performing a join query but the loader doesn't update the UI.
If I close the app and then open it then the new data appears but after inserting new data in one activity and then returning to my main activity, the data hasn't updated. The loader isn't being called despite the database have new data inserted to it.
I am calling cursor.setNotificationUri(getContext().getContentResolver(), uri); for my new join URI.
Is there any particular reason why this isn't working? Like I said the loaders work fine for standard querying of individual tables but a loader with a join query doesn't.
Is it that a loader can only listen to a single table being updated hence why it can't listen to the join?
EDIT:
Some more information about the workflow...
Activity 1 reads data using a join query of the separate tables and displays to the UI Activity 2 inserts data into separate tables to the database
Activity 1 launches Activity 2 which finishes after inserting data
Activity 1 has a loaders to update the UI. Loaders reading from individual tables works fine but a loader reading from a join query doesn't get called when data is updated. It is only called when the activity is created.
Upvotes: 3
Views: 477
Reputation: 456
I Know this question was asked a long time ago but hopefully it will help some others experiencing the same problem... I had exactly the same issue
In your Query method in your Content Provider Class, before you set the notification Uri. Make sure the Update and Delete Uri's are the same as the query Uri's.
uri = Uri.parse("content://com.casselsinthecloud.cloudbeats.provider/playlist_contents");
Then call setNotificationUri(...) with the new Uri..
cursor.setNotificationUri(getContext().getContentResolver(), uri);
This will ensure the CursorLoader is updated dynamically..
Upvotes: 1