I am new to android can any one tell me what is the difference between cursor.setNotificationUri()
and getContentResolver().notifyChange(uri,null)
while implementing content provider.
I have seen that cursor.setNotificationUri()
is used in query()
method and while updating or inserting getContentResolver().notifyChange()
is used.
I have little understanding that getContentResolver().notifyChange()
notifies resolver that some data has been changed but what does cursor.setNotificationUri()
do there ?
They are used symbiotically. If you are implementing a ContentProvider
, essentially when someone queries your provider, you produce a Cursor
and call setNotificationUri()
on it with some rational Uri
(such as the Uri
used to make the query). Later, if data served by your ContentProvider
changes, e.g. after an insert/update/delete, you call getContentResolver().notifyChange(uri, null)
so that anyone who currently has a Cursor
(because they queried earlier) gets notified that data has changed and they should re-query. If they are using a CursorLoader
, the re-query happens automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With