Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between cursor.setNotificationUri() and getContentResolver().notifyChange(uri,null)

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 ?

like image 354
FaisalAhmed Avatar asked Dec 06 '22 16:12

FaisalAhmed


1 Answers

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.

like image 118
Karakuri Avatar answered Apr 19 '23 22:04

Karakuri