Upgrade Android app and keep old SQLite database - android

I'm writting a small app for gym exercises. I keep my records in SQLiteDatabase and I want this app to start running as fast as I finish main part of the app. But further I want to develop this app and add some more features. There will be some records in a database yet. How can I save this records and move it to new version of the app? I'm developing with Android Studio, and each run app is installed from the scratch(before previous version is unistalled and all data is deleted?) if there were any changes, right? So, how can I keep old records and add them to new version app? I have seen some answers with onUpgrade, but it wasn't that specific that i can understand them, beacause they don't tell anything about upgrading only app, not the databse. And sorry for my English :)

Installing a new version of your app doesn't necessarily remove its data (unless you uninstall it manually before installation or just clear data manually).
Also, if you change your database structure in an update, you can override
SQLiteOpenHelper's onUpgrade method in order to handle database updates properly.

Related

Will sqlite database with user infomations gets deleted or reset after new update of app

I have a question related to database, i know this is not a right platform related to question but i know here i can find great developer.
My query is,
"I am going to develop an app which deal with SQLite
Database and a lots of data into the App and user saves a lot data.
so, what if i release new update to play store and user update the app;
will the user get all the data from the SQLite they saved in the previous version of app 'or' the user have to save info again into the database?"
No, it won't get deleted.
Database will get deleted if it meets following scenarios :
If developer programmatically tries to clean data of the app / User clears data of the app from App info page.
if Developer upgrades Database version after update (It'll call onUpgrade() method in SQLiteOpenHelper & developer has cleared all
table content there).
It depends on the way you are using the database, but in general what you are searching for is "database migration". You can define how the database should behave on an update (database version increased). If you did not modify your database schema, then it will stay the same as before updating the app.
In case you use room: Migrating Room databases
In case you use SQLiteOpenHelper: onUpgrade

How Exactly Updating Play Apps Occur

The Question is how exactly google play updates apps.
I mean does it remove older app exactly from files or it just append on it .
For example in my app i have a local database ,after update, will my older local database become removed?
Your old application is definitely deleted. Your app is compiled and packaged, it won't be opened by Google.
As far your database, if you made changes to your database you need to change the "database version" before publishing. And put code inside the onUpgrade() method of your SQL database. This is how you can successfully change your database. If you want to delete the old database, you can delete it inside the method. The database is on the user's device, and will stay there forever until they delete your app or your code deletes it.
I hope I'm understanding your question.

Auto update db schema with existing Android app

I have published an earlier version of my app on Play Store which had no db. Now I made a lot of changes as per the requirements and added several tables in my app.
I just want to confirm when I push this new app on Play Store, do all my existing users will easily open the app or they will get FC as there is no db exists in their app?
Please suggest me what will happen and what should I do to not let my users facing FC.
Thanks
As in your previous app you have not set database, so just initialize your database on your first screen like in splash screen.
So as soon as user will start application first database will be created and then app will start so there will not be any kind of issue or app crash scenario user will face.
Use a class derived from SQLiteOpenHelper, which automatically manages creating or updating the database when needed.
Also see When is SQLiteOpenHelper onCreate() / onUpgrade() run? (which is not your problem).

do i have every time to change the database number even if i did not make any changes to my database structure to be published to google play store

I have published my android app in google play store it works fine and perfect(my app first will go and create a sqlite DB using SQLiteOpenHelper class then the index.html page will be displayed) then i noticed that users with android version 2.3.6 have error when they install the app i solved the problem without changing or adding to the structure of the DB then after publishing the new version of my app without changing the version of the database my app will not show the index.html and i think it will keep trying creating the database and the user will just see the loading message only.
So do i have every time to change the database number even if i did not make any changes to my database structure to be published to google play store.
No, you only change the database version number to a higher version ONLY if you change the structure of the database or decide to automatically add data.
For example, you can start with version 1 with a database that contains only one table: let's call it User, and the table has a column called Username. You run the query to create the table on your onCreate method. Then you release the app.
Then you decide to add more features to the app, and implement a version of the app that did not require any database changes at all. Your db version stays 1.
Then on your next app version, you decide to add a column to the User table. So what you do, is increment the db version to 2, and then run the alter table statement on your onUpgrade method. Then you release the app.
I believe your issue lies somewhere else. Check your database data integrity and that it fits your app's model.

Strategy for updating Android app (with database)

Please forgive me if this question has been answered - I searched and couldn't find it.
I have an Android app that I want to upgrade, and it uses a SQLite Database. I want to update some of the application logic in the app, but there will be no updates to the database schema or contents. I basically need to keep the database exactly as-is for the user.
Do I need to do anything in onUpgrade to ensure that the database is kept, or can I leave the DB stuff alone for this update?
The onUpgrade() method is used incases of version change. Which means the database stored in the phone needs to be altered or dropped or deleted and a new database to be created. As your application does not have any of these requirements you can leave the DB stuff for this update.
This related article may help you with your question.
The way that I understand it, is that you need to put your database changing code in onUpdate() if you WANT to update between versions. But since you don't intend to, and are probably keeping the database version the same, then you will most likely have no issues at all.
Upgrading will NOT interfere with SQLite. Changes to db structure will not be implemented unless you programmatically do so (in onUpgrade method) or you uninstall and reinstall your app.
As long as it is the SAME application that you are upgrading, your db will not be affected and your data will not be affected either. If you change the signing key used in building your apk, your db will be recreated.
Conversely, if you change database structure at any given point, your onUpgrade method will come into play. You will be forced to backup, drop, recreate and repopulate tables which have been changed between versions (oher tables remain untouched both in structure and in data).
NOTE: In debugging, i just uninstall and reinstall the app every time i make db changes, but in production you DONT want to do that.

Categories

Resources