Android Realm issue with setDefaultConfiguration -
i've got problem realm , method setdefaultconfiguration. indeed, app multi user, , need switch between several realm configurations.
during main activity loading, configure realm configuration this:
string bddname = string.format("%s.realm",userid); userfolder = new file(getapplicationcontext().getfilesdir() + "/" + userid); config = new realmconfiguration.builder(userfolder) .name(bddname) .schemaversion(2) .migration(new realmmigration2()) .build(); realm.setdefaultconfiguration(config);
but, if try configure twice same config, realm send me error:
configurations cannot different if used open same file.
is possible test whether current configuration different 1 want set? i've tried :
if(!config.equals(realm.getdefaultinstance().getconfiguration()))
but @ first launch of activity, realm return error, because no default instance set.
i'm turning around because it's impossible test realm configuration before setting it. me ? thank lot.
edit : solution doesn't work too, i've got same error, however, realmfilename different:
try{ //first time, realm not configure, it's catched. //else, set default config if config different if(!config.getrealmfilename().equals(realm.getdefaultinstance().getconfiguration().getrealmfilename())){ realm.setdefaultconfiguration(config); } } catch (exception e){ realm.setdefaultconfiguration(config); }
the problem creating 2 instances of realmmigration2
class. if don't override equals in class:
realmmigration migration1 = new realmmigration2(); realmmigration migration2 = new realmmigration2(); migration1.equals(migration2) == false
which cause comparison of realmconfigurations fail.
so should either make realmmigration instance singleton or override hashcode()
/equals()
.
Comments
Post a Comment