sockeqwe
sockeqwe

Reputation: 15929

Realm Database is always empty after restart

I have a Realm based application where I save some data in. I also query that data afterwards on different screens by opening (and closing) different Realm instances via Realm.getDefaultInstance() and all works as expected. But, after each Restart of the app the realm database is empty.

I'm not using Realm's in memory feature and not deleteRealmIfMigrationNeeded().

My configuration looks like this:

RealmConfiguration realmConfig =
        new RealmConfiguration.Builder(context.getApplicationContext()).build();
    Realm.setDefaultConfiguration(realmConfig);

And then I use Realm.getDefaultInstance().

Upvotes: 1

Views: 1755

Answers (2)

EpicPandaForce
EpicPandaForce

Reputation: 81539

Realm clear shouldn't happen unless you either do:

1.) deleteIfMigrationNeeded() and then modify the schema

2.) use inMemory() realm and your process died at some point

3.) call Realm.deleteAll() somewhere in your code

4.) you manually delete the Realm file

Upvotes: 2

breakline
breakline

Reputation: 6073

Are you sure you're calling commitTransaction properly?

If you call the same getDefaultInstance() even on multiple screens you get back the data since its in Realm, but you need to use commitTransaction() to write it to disk.

Upvotes: 2

Related Questions