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

How to upgrade data? #126

@jinfatimay

Description

@jinfatimay

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. 😞

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions