question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't initiate Realm Configuration in AttachBaseContext in Application Class.

See original GitHub issue

Expected 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:closed
  • Created 6 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
Zhuindencommented, Oct 9, 2017

@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.

0reactions
cmelchiorcommented, Oct 10, 2017
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found