I want to import existing token
into tokenList
as first item , for example if someone has a
token="abc"
after migration
, i want he/she has tokenList
that tokenList[0]=="abc"
This is my migration code:
public class RealmMigration implements io.realm.RealmMigration {
.
.
.
if (oldVersion == 3) {
final RealmObjectSchema bankSchema = realmSchema.get("Bank");
final RealmObjectSchema tokenSchema = realmSchema.get("Token");
DynamicRealmObject bank = realm.createObject("Bank",1);
Token token = bank.get("Token");
bankSchema.addRealmListField("tokenList", tokenSchema);
List<Token> tokenList = bank.get("tokenList");
if (token != null) tokenList.add(token);
bankSchema.removeField("Token");
}
}
I replace this in new version :
@RealmField(name = "tokenList")
private RealmList<Token> mTokenList;
With this in old version in my class :
@RealmField(name = "Token")
private Token mToken;
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…