On this page
Before you can access a synced realm from the client, you must:
Synced realms use Atlas Device Sync to store data both on the client device
and in your synced data source. Opening a synced realm works exactly
like opening a local realm, except you use
to customize the settings for synced realms.
When your application uses Flexible Sync, call
sync configuration builder method
with an instance of
to open a synced realm. In the
configure() method, instantiate
UnmanagedSubscription with a name and query using
Pass your new subscription
add() method of the MutableSubscriptionSet
parameter to add it to your subscriptions:
For more information about subscriptions, see Subscribe to Queryable Fields.
Synchronous Reads and Writes on the UI Thread
By default, you can only read or write to a realm in your
application's UI thread using
asynchronous transactions. That is,
you can only use
Realm methods whose name ends with the word
Async in the main thread of your Android application unless you
explicitly allow the use of synchronous methods.
This restriction exists for the benefit of your application users:
performing read and write operations on the UI thread can lead to
unresponsive or slow UI interactions, so it's usually best to handle
these operations either asynchronously or in a background thread.
However, if your application requires the use of synchronous
realm reads or writes on the UI thread, you can explicitly allow
the use of synchronous methods with the following
You can open a synced realm when offline with the exact same syntax that you use to open a synced realm while online. Not all SDKs follow this pattern, so cross-platform developers should consult the documentation for each SDK to learn more.
It is important to remember to call the close() method when done with a
realm instance to free resources. Neglecting to close realms can lead to an