java - How do I get the realm path in order to make a migration? -


how realmpath if i'm trying migration? have this:

try {     realm realm = realm.getinstance(this); } catch (realmmigrationneededexception e) {     realm.migraterealmatpath(???, new migration()); } 

also, have following versions:

  • version 1 no realm
  • version 2 realm
  • version 3 realm migrations

how make sure users upgrade version 1 version 3 , directly install version 3 updated latest schema version number (since don't need run migration)?

those going v2 v3 version bump result of migration running, not sure how set realm schema version.

christian realm here. current migration api still rough around edges, way doing migration increments version number. below best way around currently.

// pseudo code public static class realmhelper {     private static sharedpreferences prefs;     public static realm getinstance(context context) {         string realmpath = new file(context.getfilesdir(), "default.realm").getabsolutepath();         if (prefs.getboolean("firstrun", true)) {             realm.migraterealmatpath(realmpath, new realmmigration() {                 @override                 public long migrate(realm realm, long oldversion) {                     return 42; // new version of realm                 }             });             prefs.edit().putboolean("firstrun", false).commit();         }          try {             return realm.getinstance(context);         } catch (realmmigrationneededexception e) {             realm.migraterealmatpath(realmpath, new custommigration());             return realm.getinstance(context);         }     } } 

we hoping make lot better soon: https://github.com/realm/realm-java/pull/880


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -