简体   繁体   中英

database onUpgrade

I have a question regarding the upgrade procedure of an App, more specifically, upgrading or changing the database.

Considering I have version 1 of testapp.apk. This version have DB version 1, the new version of testapp.apk have DB version 2. Now, if I were to upgrade my testapp.apk, will the onUpgrade from the old version get called before the upgrade, or will it simply call the new version´s onUpgrade?

It will run the new version. While upgrading the app, it doesn't run, it just copies the new app over the old app. Then when it runs, it'll only have the new version of the onUpgrade().

The onUpgrade code will only be called on the latest installed apk.

Your new testapp.apk will be installed first. Then, when the database is accessed for the first time, the SQLiteOpenHelper will check the existing version of the database and compare it to the new version you have specified in testapp.apk.

If the new version is greater than the old version, onUpgrade will be called on the SQLiteOpenHelper in your new testapp.apk.

Please see my answer to a similar question here as I think it will help explain the mechanics of onCreate/onUpgrade/onDowngrade.

how do i create the database in my android app?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM