Notification/Event for row and column level observation in Content Provider

浪子不回头ぞ 提交于 2019-12-11 09:08:24

问题


I have content provider which has one Table. I would like to know when ever the table rows are modified. I am using Content Observer for the Table URI, which does tell when the table is modified. However it does not give much information about which row is modified, also which columns are modified. I am looking for something similar to iOS API "handleManagedObjectContextDidChangeNotification".Is there any Open source library or API available for row and column level observation?


回答1:


ContentObserver, and the whole ContentProvider framework, does not support what you want.

If the provider and its consumers are in the same app, you can use an event bus to raise more fine-grained events. Common event bus implementations include LocalBroadcastManager, greenrobot's EventBus, and Square's Otto.

If the provider and its consumers are in separate app, you will be limited to using system-level broadcasts or similar IPC mechanisms for which you can better control the protocol.




回答2:


Send an id based URI to your contentobserver. The contentObserver can then use the id to get to the row that was changed.

example rowid 323 of mytable in uri.

content://com.example/mytable/323

Sorry I don't have access to my android dev from this pc or I could give a more accurate example.



来源:https://stackoverflow.com/questions/29105582/notification-event-for-row-and-column-level-observation-in-content-provider

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