Open & Close a Local Realm - Android SDK¶
On this page
Open a Local Realm¶
Close a Realm¶
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
Local Realm Configuration¶
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
Use the readOnly() method when configuring your realm to make it read-only:
To create a realm that runs entirely in memory without being written to a file, use the inMemory() method when configuring your realm:
To open a Dynamic Realm with a mutable schema, use DynamicRealm:
The Default Realm¶
Realm modules are collections of Realm object models. You can selectively include individual modules when opening a realm.
Libraries that include Realm Database must expose and use their
schema through a module. Doing so prevents the library from
generating the default
RealmModule, which would conflict with
RealmModule used by any app that includes the library.
Apps using the library access library classes through the module.
Set the Client Log Level¶
Realm uses the log levels defined by Log4J.
To diagnose and troubleshoot errors while developing your application, set the
log level to
trace. For production deployments, decrease the
log level for improved performance.