问题描述
我写了一个小应用程序的健身运动。我保持我的记录在SQLiteDatabase,我想让这个应用程序开始运行,就像我完成的应用程序的主要部分一样快。但进一步,我想开发这个程序,并添加一些更多的功能。数据库中还有一些记录。如何保存此记录并将其移动到新版本的应用程序?我正在使用Android Studio进行开发,每个运行应用程序是从头开始安装的(如果有任何更改,则之前的版本将被卸载并删除所有数据),是吗?那么,我如何保留旧的记录并将它们添加到新版本的应用程序?我已经看到一些答案与onUpgrade,但它不是那么具体,我可以理解他们,因为他们不告诉任何关于只升级应用程序,而不是数据库。对不起我的英语:)
I'm writting a small app for gym exercises. I keep my records in SQLiteDatabase and I want this app to start running as fast as I finish main part of the app. But further I want to develop this app and add some more features. There will be some records in a database yet. How can I save this records and move it to new version of the app? I'm developing with Android Studio, and each run app is installed from the scratch(before previous version is unistalled and all data is deleted?) if there were any changes, right? So, how can I keep old records and add them to new version app? I have seen some answers with onUpgrade, but it wasn't that specific that i can understand them, beacause they don't tell anything about upgrading only app, not the databse. And sorry for my English :)
推荐答案
安装新版本的应用程序不一定会删除其数据
Installing a new version of your app doesn't necessarily remove its data (unless you uninstall it manually before installation or just clear data manually).
此外,如果在更新中更改数据库结构,可以覆盖
的方法,以便正确处理数据库更新。
Also, if you change your database structure in an update, you can overrideSQLiteOpenHelper's onUpgrade method in order to handle database updates properly.
这篇关于升级Android应用程序并保留旧的SQLite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!