开发者

order of ContentObserver notifications

I'm querying a ContentProvider, looping thru the rows in the cursor, creating an object for each row and adding that object to a list. I'm registering each object as a ContentObserver of its own uri. That's working fine, the objects are getting notified when their DB row is updated and/or deleted. My problem is that if the DB row is deleted how I know to remove it's corresponding object from the list?

In the object's onChange() method, I'm querying the ContentProvider for it's _id and if I get no results back, I'm setting a "deleted" flag. I've also registered the list (actually a ContentObserver wrapper around the list) as a ContentObserver for the main ContentProvider uri, and in that onChange() method, I loop thru the list and check the "deleted" flag of each object in the list and remove it from the list if deleted==true.

However, it seems that the list is getting notified BEFORE the individual objects are...hence, as I loop thru the list the relevant object's "deleted" flag is not yet set.

Is there any way to control the order in which ContentObservers get notified of changes? since the docs don't say anything, I suspect the answer is "no", but thought I'd ask.

The current situation isn't that bad, since the next time the list gets a notification, it will remove t开发者_运维百科he previously deleted object, hence, I have at most 1 extra object in the list...but there must be an "approved" way of handling this, but as I'm new to Android development I haven't been able to figure out what it would be. Any suggestions?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜