Java – What is the difference between getDefaultInstance() and getInstance() in Realm?

What is the difference between getDefaultInstance() and getInstance() in Realm?… here is a solution to the problem.

What is the difference between getDefaultInstance() and getInstance() in Realm?

What is the difference between realm.getDefaultInstance() and realm.getInstance(context)? In general, when would you choose one of them?

Solution

The getDefaultInstance() method instantiates the Realm using the default RealmConfiguration.

getInstance (RealmConfiguration configuration) returns instances using your configuration, such as database name, schemaVersion, migration, some of which are required in real-world applications. Especially if the Realm platform is in sync.

But if you use getDefaultInstance() in many places in your application, to avoid calling the configuration every time, you can use setDefaultConfiguration(RealmConfiguration) and then getDefaultInstance(). Your configuration will always be used to return to the Realm instance.

Related Problems and Solutions