Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

How to upgrade data? #126

Open
jinfatimay opened this issue Jan 3, 2018 · 2 comments
Open

How to upgrade data? #126

jinfatimay opened this issue Jan 3, 2018 · 2 comments

Comments

@jinfatimay
Copy link

jinfatimay commented Jan 3, 2018

tray Version

0.12.0

How have you setup tray

Initialized in Application.onCreate

Device(s)

too many (samsung, huawei, google, etc.)

Android Version

from 4.4 to 7

Description

I traced the code. Tray will upgrade version in constructor (it will call isVersionChangeChecked()).

In isVersionChangeChecked(), it will check version(changeVersion()) to do onCreate/onUpgrade/onDowngrade if mChangeVersionSucceeded == false.

Notice that the variable mChangeVersionSucceeded is always false until the last line in changeVersion() (after finishing onCreate/onUpgrade/onDowngrade)
And the new version value (getStorage().setVersion(newVersion)) is also set after finishing onCreate/onUpgrade/onDowngrade

Assume I want to toggle a boolean value in new version. I write the code like ...

@Override
protected void onUpgrade(int oldVersion, int newVersion) {
        put(key, !getBoolean(key, false));
}

However, at the beginning of put method is...

if (!isVersionChangeChecked()) {
     return false;
}

It calls isVersionChangeChecked() again!
At that time, mChangeVersionSucceeded is still false and getStorage().getVersion() is also the old version.
So...it will passes all IF statements then calls onUpgrade again and again.

Please teach me how to fix this issue? 😃
Sorry, I'm not good at English. 😞

@jinfatimay
Copy link
Author

I found a way...
I can use storage directly to save the value I want to upgrade.
Is that a good way..?

@Polyterative
Copy link

I guess it is

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants