【发布时间】:2018-12-10 06:11:19
【问题描述】:
我有一个应用程序,我在其中使用我提供的 SQLite 数据库,所以它是固定的,用户不会更新数据库中的任何内容。只会显示来自该数据库的结果。
问题是 - 我仅在应用程序首次运行时以编程方式创建该数据库:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if(!prefs.getBoolean("firstTime", false)) {
final DatabaseHelper myDb;
myDb = new DatabaseHelper(this);
myDb.deltab();
myDb.insertData("Josh","Smith","012345678","something","something","something");myDb.insertData("Josh","Smith","012345678","something","something","something"); }
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("firstTime",true);
editor.apply();
首先我删除表(只是为了确保它会从头开始创建它),然后我创建它并插入数据。
这在第一次运行应用时运行良好。
但如果我以后需要在该表中添加更多数据,或者在下一个应用版本中更改任何现有数据,我该怎么做?
如果用户下载了新版本的应用程序,firstTime 条件不会运行,因为他之前已经启动了旧应用程序并且通过升级版本不会重置共享首选项。
【问题讨论】: