How to update my application by APK without losing my Sqlite database?

Asked

Viewed 1,435 times

5

I created an app, I registered at the bank Sqlite, but when I create new functions for the application how do I update without uninstalling it?

Obs: no use Google Play, I install direct from Apk that I create.

  • 1

    Change the app without updating it think you have no way, you need a way to update the APK (as occurs in the play store), give a look at the link that follows: How to make a manual system to check for new updates?

  • i want to update it, but without uninstalling the application, do not want to lose the information in the bank

  • 1

    @Tahatsu take a look at the answer How to update a proprietary app?

  • No need to lose the information, only happens if you program to delete in the installation.

  • 1

    How are you doing to create the Bank? .

  • 1

    the bank must be in a device user folder.

  • 1

    When you update you don’t lose the bank. Unless you uninstall the already installed application.

  • 1

    If you just install the apk "above" the previous version, practically an update doesn’t happen. Now if uninstall the app ai was already the bank, unless you did as @Danielomine said and the bank is in an "out" folder of the app, depending on the situation may not be a good idea, but it is an alternative.

  • 2

    If you want to change the database, create columns or tables you should do Migration in your app, or write the script to give the "upgrade" in your database, you can use the Sqliteopenhelper that is already native on android, here there is an example.

Show 4 more comments

1 answer

1


When you update your APK in the playstore your database will NOT be deleted. In your databasehelper class you will have a method onUpgrade(Sqlitedatabase db, int oldVersion, int newVersion) where oldVersion is the previous version of your database on the user device and newVersion is the new version.

Example

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    switch (oldVersion){
        case 1;
            //TODO alteras campos da vesao 1 para versão 2
            break;
        case 2;
            //TODO alteras campos da vesao 2 para versão 3
            break;
        case 3;
            //TODO alteras campos da vesao 3 para versão 4
            break;
    }
}

If you need to know the new version of the database to make the change use the variable newVersion

Browser other questions tagged

You are not signed in. Login or sign up in order to post.