FaisalAhmed FaisalAhmed - 29 days ago 19
Android Question

Diference 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 new getContentResolver() is used.

I have little understanding that
getContentResolver()
notify resolver that some that has been changed but what does
cursor.setNotificationUri()
does there ?

Answer

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.