realm-java icon indicating copy to clipboard operation
realm-java copied to clipboard

keep realm db after android app update

Open Ksernik opened this issue 9 years ago • 5 comments

Hi everyone =) I have the problem with app updating. When users update my app from Market, they lose authorization data, which are recorded in db. I found post on stackoverflow, but there is no answer.. (https://stackoverflow.com/questions/42527530/keep-realm-db-after-android-app-update) What can i do for keep session data?

Realm init:

RealmConfiguration config = new RealmConfiguration.Builder(this)
                .name("myapp.realm")
                .schemaVersion(mRealmSchemaVersion)
                .deleteRealmIfMigrationNeeded()
                .build();
Realm.setDefaultConfiguration(config);

(schemaVersion is not change)

Realm version: 1.0.1 Android Studio version: 2.3.2 Which Android version and device: this is mass problem

Thanks for answers or advice =)

Ksernik avatar Jun 29 '17 10:06 Ksernik

The Realm file on disk doesn't get deleted when people upgrade your app, but you have set deleteRealmIfMigrationNeeded(). This will delete the file if you changed the Realm schema somehow. You need to set a schema version and migration instead. See https://realm.io/docs/java/latest/#migrations

cmelchior avatar Jun 29 '17 10:06 cmelchior

yes, i know it, but Realm schema does not change))) ok, thanks, i will try set migration

Ksernik avatar Jun 29 '17 10:06 Ksernik

yep, seems all work fine with migration =) thanks a lot! =)

Ksernik avatar Jun 30 '17 06:06 Ksernik

How to make it . Please explain me.

kzdeveloper12345 avatar May 31 '18 03:05 kzdeveloper12345

@kzdeveloper12345 here is an example: migration-example

But you can reference the code in this to know how to handle complex cases like changing primary key, or adding primitive lists

Zhuinden avatar May 31 '18 09:05 Zhuinden