How to get URI of inserted row in my content observer?

自闭症网瘾萝莉.ら 提交于 2019-11-29 15:28:33

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.

Thomas

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 =(

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!