Search code examples
androidrealm

Configure Realm in Activity


According to the Realm documentation:

The RealmConfiguration can be saved as a default configuration. Setting a default configuration in your custom Application class makes it available in the rest of your code.

Would I run into any issues if I init realm in my application class but do the configuration in an activity?

During realm migration, I rely on values returned during a network call made from our Splash Screen Activity and just want to make sure doing it this way won't cause any issues down the road.


Solution

  • do the configuration in an activity?

    That works as long as you do that in a BaseActivity of sorts, otherwise process death will kill you if you restore the app from an Activity that does not set the configuration.


    Although you can be certain that the very first Activity that is open after a version update is the Splash (or ACTION_MAIN) so the migration would work there.

    Are you using Realm.getInstanceAsync()?