基于Android的什么境界迁移版本号? [英] Android Realm Migration version number based on what?
问题描述
我在做我的第一个域迁移,并开始思考的版本号。关于什么是基于这个版本号?
I'm doing my first Realm migration and started thinking about the version number. On what is this version number based?
由于它是否是基于什么是您的手机上,我该如何处理呢,如果换了一个人安装应用程序,并得到了迁移?因为它也将更新它在这里已经设置,因为领域的全新安装。
Because if it is based on what is on your phone, how do I handle it if a new person installs the app and gets a migration? Because it will also update the fields which where already set because of a fresh install.
推荐答案
从这里境界的基督徒。迁移API仍然是一个非常实验状态,有点丑,所以现在的版本号总是以0开始,改变,唯一的办法就是通过移民。
Christian from Realm here. The migration API is still in a very experimental state and kinda ugly, so right now the version number always start with 0, and the only way for changing that is through a migration.
这意味着,如果你想要一个新鲜比0的不同版本上安装,你将不得不做这样的事情:
This means that if you want a fresh install with a different version other than 0, you will have to do something like:
// Pseudo code
public class RealmHelper() {
private static SharedPreferences prefs;
public static Realm getInstance() {
if (!prefs.getBool("versionSet", false)) {
String path = new File(context.getFilesDir(), Realm.DEFAULT_REALM_NAME).getAbsolutePath();
Realm.migrateRealmAtPath(path, new RealmMigration() {
@Override
public long execute(Realm realm, long version) {
return 42; // Set version numbers
}
})
prefs.setBool("versionSet", true)
}
return Realm.getInstance();
}
}
这将是好了很多,不过很快:<一href=\"https://github.com/realm/realm-java/pull/929\">https://github.com/realm/realm-java/pull/929
This is going to be a lot better soon though: https://github.com/realm/realm-java/pull/929
这篇关于基于Android的什么境界迁移版本号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!