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. 😞
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 doonCreate/onUpgrade/onDowngradeifmChangeVersionSucceeded == false.Notice that the variable
mChangeVersionSucceededis alwaysfalseuntil the last line inchangeVersion()(after finishingonCreate/onUpgrade/onDowngrade)And the new version value (
getStorage().setVersion(newVersion)) is also set after finishingonCreate/onUpgrade/onDowngradeAssume I want to toggle a boolean value in new version. I write the code like ...
However, at the beginning of put method is...
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
onUpgradeagain and again.Please teach me how to fix this issue? 😃
Sorry, I'm not good at English. 😞