Can any one please let me know i have Test.realm file which is exported by me from Another Project.I want to read and use this file in my project(On Android Platform).I am already using realm for my application.
I am placing the file in assets folder;can you please let me know how to access this file.
RealmConfiguration.Builder has a method named assetFile(), if you set that filename as parameter then it'll be used as source of initial Realm
public RealmController(Context application) {
realmConfiguration = new RealmConfiguration.Builder(application)
.deleteRealmIfMigrationNeeded()
.schemaVersion(DB_VERSION).build();
// Clear the realm from last time
Realm.setDefaultConfiguration(realmConfiguration);
realm = Realm.getInstance(realmConfiguration);
}
I am using this default realm of my app can you please let me know how to read another .realm file in Parrallel.
You can have multiple configurations in an app, and you can get instances of them. Realms cannot be mixed. For example, you cannot query multiple Realms in a single query. Moreover, you will have to manually copy objects from one Realm to the other (combining copyFromRealm() and copyToRealm() is one way).
Can you please send me the code snippet how to read .realm file from asset folder in android;with parallel using my default realm schema.
private void getData(){
RealmConfiguration config1 = new RealmConfiguration.Builder(this)
.assetFile(this,"data/BizGeo.realm")
.schemaVersion(30)
.build();
Realm realm = Realm.getInstance(config1);
realm.close();
LogManager.d("Sheet list size","Size"+list.size());
}
i am using this code
But throwing error
java.lang.IllegalArgumentException: Configurations cannot be different if used to open the same file.
Cached configuration:
realmFolder: /data/user/0/com.example.hats/files
realmFileName : default.realm
canonicalPath: /data/data/com.example.hats/files/default.realm
key: [length: 0]
schemaVersion: 30
migration: null
deleteRealmIfMigrationNeeded: true
durability: FULL
schemaMediator: io.realm.DefaultRealmModuleMediator@d079674f
New configuration:
realmFolder: /data/user/0/com.example.hats/files
realmFileName : default.realm
canonicalPath: /data/data/com.example.hats/files/default.realm
key: [length: 0]
schemaVersion: 30
migration: null
deleteRealmIfMigrationNeeded: false
durability: FULL
schemaMediator: io.realm.DefaultRealmModuleMediator@d079674f
at io.realm.RealmCache.validateConfiguration(RealmCache.java:251)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:114)
at io.realm.Realm.getInstance(Realm.java:192)
You need to specify two different file name. Just use name() in your configuration: https://realm.io/docs/java/3.0.0/api/io/realm/RealmConfiguration.Builder.html#name-java.lang.String-
RealmConfiguration config1 = new RealmConfiguration.Builder(this)
.assetFile(this,"data/BizGeo.realm")
.name("BizGeo.realm")
.schemaVersion(30)
.build();
RealmConfiguration config2 = new RealmConfiguration.Builder(this)
.name("somethingElse.realm") // not required: default.realm is fine
.build();
You might wish to use module() if you don't have the exact same classes in both configurations.
Indeed, you need to specify name("[filename].realm") to open the asset realm into a different Realm file, the default name is default.realm.
What is RealmController?
Hope your issue is solved. Feel free to reopen this if needed.
Most helpful comment
You can have multiple configurations in an app, and you can get instances of them. Realms cannot be mixed. For example, you cannot query multiple Realms in a single query. Moreover, you will have to manually copy objects from one Realm to the other (combining
copyFromRealm()andcopyToRealm()is one way).