Realm: Use One Or Multiple Realms In An App (and One Or Multiple Schemas)
I'm implementing an app that persists data at some points (not related between them) using Realm. In example: Save the items favorited by the user. (The app have a chat) Save the
Solution 1:
If your data is really completely disconnected, I would go with option C) It makes for a clean separation. Migrations are easier to handle, and there is also a very small performance gain as Realm has to loop through all model classes in a Realm from time to time.
But none of the options are "wrong".
Solution 2:
Yes you can, although you can would usually have multiple classes in on Realm
Configuring Other Reams shows how to specify different file paths, eg:
RealmConfigurationmyConfig=newRealmConfiguration.Builder(context)
.name("myrealm.realm")
.schemaVersion(2)
.modules(newMyCustomSchema())
.build();
RealmConfigurationotherConfig=newRealmConfiguration.Builder(context)
.name("otherrealm.realm")
.schemaVersion(5)
.modules(newMyOtherSchema())
.build();
RealmmyRealm= Realm.getInstance(myConfig);
RealmotherRealm= Realm.getInstance(otherConfig);
@RealmModule(classes={Abc.class, Pqrs.class, Xyz.class})classMyCustomSchema{}
@RealmModule(classes={Abc1.class, Pqrs2.class, Xyz2.class})classMyOtherSchema{}
Post a Comment for "Realm: Use One Or Multiple Realms In An App (and One Or Multiple Schemas)"