如何数据库信息保存到android系统中的文件? [英] How to save database information to a file in android?

查看:383
本文介绍了如何数据库信息保存到android系统中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用pre-polulated数据库列出事件的应用程序。该应用程序允许人们通过一个1设置为列isFavorite保存这些事件他们的最爱。然后,用户只能查看一个收藏的事件列表,其中搜索有isFavorite = 1。

I have an application that uses a pre-polulated database to list events. The app allows people to save these events to their favorites by setting a '1' to the column isFavorite. Then the user can view only a list of 'favorited' events which searches for all rows that have isFavorite = 1.

如果任何改变发生的事件或我需要更多的添加到列表中,我必须做出这些变化,然后将更新推到完全写在桌子上,清理出自己喜爱的应用程序。

If any changes happen to the events or I need to add more to the list, I have to make those changes and then push the update to the app which completely writes over the table, clearing out their favorites.

有什么办法,我可以,在升级,节省他们已经设置为自己喜爱的所有事件的ID的列表,之后再将新的数据库已加载,将所有的ID在该列表中为1,用户不会丢失其收藏的数据?

Is there any way that I can, on upgrade, save a list of id's of all the events that they have set to their favorites, then after the new database has been loaded, to set all id's in that list to 1 so the user doesn't lose their favorited data?

如果有任何其他更好的解决问题的对策,我真的AP preciate它,这一直是最大的障碍,我至今。

If there are any other better solutions to this problem I would really appreciate it, this has been the biggest hurdle for me so far.

推荐答案

我猜,你有一个的 SQLiteOpenHelper 级?这个类必须扩展,然后提供两种功能:的onCreate (当查询数据库被称为它不存在(在首位通常创建数据库) )和的onUpdate (当数据库结构应该更新被查询)。

I guess, you have a SQLiteOpenHelper-class? This class must be extended and then provides two functions: onCreate (which is called when the Database is queried and it doesn't exist (Normally creates your Database in the first place)) and onUpdate (which is queried when the Database structure should be updated).

的onUpdate -method有一个 SQLiteDatabase -object参数,这是你的数据库。然后,您可以查询你需要的信息,将它们保存,然后创建新的数据库桌。在这之后,你可以在数据库中插入已保存的数据备份。

The onUpdate-method has an SQLiteDatabase-Object parameter, which is your Database. You can then Query the informations you need, save them and then create the new Database-tables. After that, you can insert your saved data back in the Database.

这篇关于如何数据库信息保存到android系统中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆