Open a Synced Realm
Flexible Sync
The Kotlin SDK does not yet support Flexible Sync. You can currently only use the SDK with Partition-Based Sync applications.
Prerequisites​
Before you can access a synced realm from the client, you must:
Enable sync in the Realm UI.
Install the sync distribution of the Kotlin SDK for Android or Kotlin Multiplatform.
Authenticate a user in your client project.
Open a Synced Realm​
To open a synced {+realm+}, pass a user, a partition, and a set of
Realm object schemas to
SyncConfiguration.Builder().
Then, pass the configuration to Realm.open()
to open an instance of the realm:
val app = App.create(YOUR_APP_ID)
runBlocking {
val user = app.login(Credentials.anonymous())
val config = SyncConfiguration.Builder(user, PARTITION)
// specify name so realm doesn't just use the "default.realm" file for this user
.name(PARTITION)
.build()
val realm = Realm.open(config)
Log.v("Successfully opened realm: ${realm.configuration.name}")
realm.close()
}
Configure a Synced Realm​
To adjust specific configuration settings, use the options provided by
SyncConfiguration.Builder:
val app = App.create(YOUR_APP_ID)
runBlocking() {
val user = app.login(Credentials.anonymous())
val config = SyncConfiguration.Builder(user, PARTITION)
// specify name so realm doesn't just use the "default.realm" file for this user
.name(PARTITION)
.path("/tmp/$PARTITION")
.maxNumberOfActiveVersions(10)
.build()
val realm = Realm.open(config)
Log.v("Successfully opened realm: ${realm.configuration}")
realm.close()
}