Before you can use Realm in your app, you must initialize the Realm library. Your application should initialize Realm just once each time the application runs.
To initialize the Realm library, provide an Android
context to the
Realm.init() static function. You can provide
an Activity, Fragment, or Application
context for initialization with no
difference in behavior. You can initialize the Realm library
onCreate() method of an application subclass to
ensure that you only initialize Realm once each time the
If you create your own
Application subclass, you must add it to your
AndroidManifest.xml to execute your custom
application code. Set the
android.name property of your manifest's
application definition to ensure that Android instantiates your
subclass before any other class when a user launches your application.
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mongodb.example"> <application android:name=".MyApplicationSubclass" ... /> </manifest>
Pass the App ID for your App, which you can find in the Realm UI.
You must initialize your Realm app connection with
Realm.init() before creating any instance of an
You can create multiple
App instances to connect to multiple
Apps or to the same App with different configurations. All
App instances that share the same App ID use the same underlying
For more granular control of the details of your app connection,
such as custom timeouts for connections, codecs used for MongoDB Data Access,
and keys for local encryption, you can use the
Builder to control details of your
For most use cases, you only need your application's App ID to connect to Realm. The other settings demonstrated here are optional.