0

Is there a way to ask Realm in Android if migration is needed?

I have my configuration in place so that realm gets deleted if migration is needed.

realmConfiguration = new RealmConfiguration
        .Builder(context)
        .deleteRealmIfMigrationNeeded()
        .build();
Realm.setDefaultConfiguration(realmConfiguration);
realm = Realm.getInstance(realmConfiguration);

This is fine for my purpose, but I need to know when this happens, because I need to store default data into the database if it has been erased. Any tips how I can react to realm deleting the data?

Terry
  • 14,529
  • 13
  • 63
  • 88

1 Answers1

1

You should use the initialData method to which you can provide an initial transaction that sets up your data - it runs if the Realm is empty, or if deleteIfMigrationNeeded() deleted your Realm.

EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428