Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android handle app updates and database changes

I have basically finished developing an android app that makes use of SQLite databases that I copy to the user data area on the device eg /data/data/com.company.app/databases/users.db

I am unsure how the marketplace app update procedure takes place and am also unsure as to how I could test it.

I currently check whether the database exists on the device and copy it if it doesn't (generally only occurs on first ever launch). What happens if I have a new version of the database in my updated app? Will an marketplace update wipe user data so that it will copy my new database in on next launch?

What happens in the future if I make database changes/add records/etc and package this with the new app? Will this database not overwrite the old database?

Otherwise, to avoid copying and overriding the databases from the app bundle on every launch is there a way to check the size and date of the database files and only copy if the database in the bundle is newer?

If anyone needs clarification please ask.

like image 507
Daniel Bowden Avatar asked Oct 14 '10 02:10

Daniel Bowden


People also ask

How do I manage app updates on Android?

At the top right, tap the profile icon. Tap Manage apps & device. Apps with an update available are labeled "Update available." Tap Update.

Do Android apps use databases?

Due to its inclusion in the Android Software Development Kit (SDK), SQLite, an open-source relational database, is the most common database technology associated with Android applications.

Where are Android app database stored?

But by default all the android application store database on internal storage path /data/data/<application_package_name>/databases . And its applicable for all devices rooted or un-rooted.

How do Android app updates work?

The developer publishes a new version (4.0). The 90-day period ends, the app is added to the update queue and will be automatically updated according to the default update behavior, once the constraints are met. The constraints are met and therefore the app is updated to the latest available version (4.0).


1 Answers

I am doing something similar. What I did is set the database version, and then when I check if the database exists, I also to make sure it's the correct version. If it's not, I save user favorites from the database, wipe and recopy my db, and then put back user favorites.

This is my on upgrade

    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    if (oldVersion == 2) {

        System.out.println("Performing upgrade!");
        openDataBase();
        // save the old favorites
        Cursor mCursor = getFavorites();
        ArrayList<Stop> favs = allCursorToStops(mCursor);
        mCursor.close();

        deleteRecreate(db);

        openDataBase();

        for (int i = 0; i < favs.size(); i++)
            setFavorite(favs.get(i));

        close();

    } else {

        deleteRecreate(db);

    }
}

Here is where I check existence/if need to upgrade etc

    boolean dbExist = checkDataBase();

    if(dbExist){
        // check if we need to upgrade
        openDataBase();
        int cVersion = myDataBase.getVersion();
        close();
        if(cVersion != VERSION)
            onUpgrade(myDataBase, myDataBase.getVersion(), VERSION);
like image 190
ibash Avatar answered Sep 23 '22 12:09

ibash