Because my new version app is to generate new database. But old version same data which causing the issue.
所以我需要卸载旧版本只维护当前版本。我可以知道实现我的目标的正确方法是什么吗?
最佳答案
在你的 SQLiteHelper 子类中实现 onUpgrade 方法。
数据库升级
The constructor of your implementation of SQLiteOpenHelper should call the super constructor, passing along the database name and version. The onUpgrade() method will only be called when the version integer is larger than the current version running in the emulator. If you want the onUpgrade() method to be called, you need to increment the version number in your code.
SQLiteHelper 代码保留您传递给构造函数的 VERSION 字段,并将其保存在数据库中。当您需要更改架构时,您可以递增此整数。
在您升级
应用程序后,应用程序中的版本号高于"disk"
上数据库中的版本号,SQLiteHelper 代码通知,并且使用新旧版本号调用 +onUpgrade()+
方法。
您应该知道每个版本之间发生了什么变化,并相应地更新
数据库架构。
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Your Staff
onCreate(db);
}
检查 SQLiteOpenHelper onUpgrade() Confusion Android
请阅读官方指南。
int, int)
关于android - 有没有办法在安装新版本时删除旧版本应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34626662/