Suppose I run some query and get a cursor which I want to use to update the entries in the database. What happens if the database is updated while the cursor is not closed? For example, suppose the cursor is pointing at the 1st entry in the result set and I run a query that updates the 10th element. Does the current cursor reflect those changes?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
The cursor is a copy of the results in memory, so you can modify the database at will. Since it's a copy, it won't reflect any changes - you'd need to requery for that.
However, it is absolutely imperative that you close it as soon as possible, to save memory and to make your app not crash when you switch activities.
回答2:
You need to call cursor.requery()
in order to reload changes from the database.