If you are talking about migratin a sql database, then SQLiteOpenHelper.onUpgrade() is the right place to put your migration code into. In this case you don't have to rely on the versionCode, but rather on the database version number. So just increment the database version number in your next app update and SQLiteOpenHelper
will automatically call onUpgrade()
. You can do queries and table definition so. you may query the whole data, load it in memory, manipulate this data in memory, change the sql table definition, clear the table and reinsert the (manipulated / migrated) data into your sql tables.
If you are talking about migrating other data (like Shared preferences, files on external storage etc.) then you may subclass Application
an override onCreate()
. Then you check if versionCode == 16
and do your migration stuff and afterwards you have to store the information that the migration has been done successful (to not rerun migration again on next app start). I would to that by saving a boolean flag into shared preferences.