0
我有一個存儲在/ data/..文件夾中的realm數據庫。當我通過android studio重新安裝相同的應用程序版本時,該過程保留數據。但是如果我從較低的應用程序版本更新到更高版本,則會將其刪除。什麼原因以及如何在應用程序更新後保留此db?遷移代碼:android應用更新後保持realm db
public class FRGMigration implements RealmMigration {
@Override
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
if (oldVersion == 3) {
realm.getSchema().create("Settings")
.addField("id", Integer.class, FieldAttribute.PRIMARY_KEY)
.addField("userName", String.class)
.addField("cachePolitics", String.class)
.addField("soundUri", String.class)
.addField("cacheDir", String.class)
.addField("timeStamp", Long.class);
realm.getSchema().get("NewsItem")
.addField("teaser", String.class);
oldVersion++;
SettingsDB settingsDB = DependencyProvider.getInstance().provideSettingsDB();
Settings settings = settingsDB.getSettings();
settings.setTimeStamp(0L);
settingsDB.updateSettings(settings);
}
}
@Override
public int hashCode() {
return 37;
}
@Override
public boolean equals(Object obj) {
return obj instanceof FRGMigration;
}
}
我確實將此參數設置爲「true」,但它在應用更新時不起作用,不幸的是 –
@ M.Maximovich您可以發佈您的「RealmConfiguration」嗎? – FiN
realmConfiguration = new RealmConfiguration.Builder().name(「settings.realm」).schemaVersion(4).migration(new FRGMigration()).build(); –