Can't initiate Realm Configuration in AttachBaseContext in Application Class.
See original GitHub issueExpected Results
Realm initialized with the RealmConfiguration.
Actual Results
java.lang.IllegalStateException: Call Realm.init(Context) before creating a RealmConfiguration
Steps & Code to Reproduce
Can’t set realm configuration in Application class in attachBaseContext. it is possible in OnCreate.
Code Sample
@Override
protected void attachBaseContext(final Context base) {
initRealm(base);
}
private void initRealm(Context context) {
Realm.init(context);
try {
RealmConfiguration configuration = new RealmConfiguration.Builder().name(REALM_NAME).schemaVersion(1).deleteRealmIfMigrationNeeded()
.build();
Realm.setDefaultConfiguration(configuration);
} catch (Exception ignore) {
ignore.printStackTrace();
}
}
Version of Realm and tooling
Realm version(s): ?
3.7.2
Realm sync feature enabled: yes/no
no.
Android Studio version: ?
3.0 b7
Which Android version and device: ?
Emulator, any android version.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
Unable to initiate application class from dynamic module
In base app, have the Application class and declared into AndroidManifest.xml file: public class App : SplitCompatApplication() { override ...
Read more >ContextWrapper - Android Developers
Because device-protected data is available without user authentication, you should carefully limit the data you store using this Context.
Read more >How to change the language on Android at runtime and don't ...
So we have a class LocaleManager that wraps a logic of changing an application locale. Let's focus on updateResources method. What we do...
Read more >FirebaseMessagingService - Google
attachBaseContext (Context base). boolean. bindIsolatedService( Intent service, int flags, String instanceName, Executor executor, ServiceConnection conn ).
Read more >Activity Class (Android.App) | Microsoft Learn
Use with #getSystemService(String) to retrieve a android.telephony.CarrierConfigManager for reading carrier configuration values. (Inherited from Context).
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@cmelchior I assume he needs to have a language set for the user depending on in-app language preferences, and this is stored in Realm, and you have to override the base context of Application to override the language or so.
We didn’t run into this problem because we stored this data in shared pref.
See https://github.com/realm/realm-java/pull/5406