简体   繁体   English

android更新记录并重新查询

[英]android update record and requery

Developing an application that displays data retrieved from it's database in the initial screen. 开发一个应用程序,以在初始屏幕中显示从其数据库检索到的数据。 Users can edit the data via a separate edit screen. 用户可以通过单独的编辑屏幕编辑数据。 Exiting the edit screen returns the user to the initial display screen, I requery the database but the data returned is the values prior to the edit. 退出编辑屏幕会使用户返回到初始显示屏幕,我重新查询数据库,但是返回的数据是编辑之前的值。

I am using a db provider model and have tried: 我正在使用数据库提供程序模型,并尝试过:

  • closing the cursor used in the initial database lookup 关闭用于初始数据库查找的游标
  • using a separate cursor each time returning to the initial screen 每次返回初始屏幕时使用单独的光标
  • using a separate query to get the data displayed on the edit screen 使用单独的查询来获取显示在编辑屏幕上的数据
  • ensure that each cursor used is closed when work with that cursors data is complete 确保在使用该游标数据完成后关闭每个使用的游标

Database queries and relaunching the application shows the edited values so I am sure that the update is working. 数据库查询和重新启动该应用程序将显示编辑后的值,因此我确定更新可以正常进行。 What am I missing? 我想念什么?

Found that the issue was related to misunderstanding states in the class used to support the editor function. 发现该问题与用于支持编辑器功能的类中的误解状态有关。 Thought the onStop() and onDestroy() would be called when exiting the edit screen and was calling the method to update the database in those methods. 以为onStop()和onDestroy()会在退出编辑屏幕时被调用,并正在调用方法以更新这些方法中的数据库。

Changed to use onBackPressed() instead and complete the update process before the updated values are displayed. 更改为改为使用onBackPressed()并在显示更新的值之前完成更新过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM