Skip to content Skip to sidebar Skip to footer

How To Get Uri Of Inserted Row In My Content Observer?

In my application, I am inserting values in database from a different class which gives me id of inserted row. I have registered an observer of it in my UI and whenever any row is

Solution 1:

When you insert the new row, you have to manually call notifyChange:

context.getContentResolver().notifyChange(uri, null);

The code that inserted the row should have access to the new rowid, and should be able to construct the URI to pass to notifyChange. When notify change is called, it should cause all ContentObservers to be updated.

Solution 2:

Now in android api 16 there is the possibility of getting the URI of the modified row in the OnChage method through a version of the onChange which takes the URI as a parameter. You can find more details about it on the Content Observer documentation http://developer.android.com/reference/android/database/ContentObserver.html

For on older api versions I am not sure if there is solution (without adding more logic such as implementing flags on your database). I asked that question regarding specifically the old api on " getting changed uri on ContentObserver Onchange on older versions of the API " and did not get any answer =(

Post a Comment for "How To Get Uri Of Inserted Row In My Content Observer?"