Auto update db schema with existing Android app - android

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).

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.

Upgrade Android app and keep old SQLite database

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.

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.

Android - SQLite

I am trying to build an app that will use an SQLite database. My question is once the database is created, will all data still be there once the app is closed, i.e.: the database won't be overwritten when the app is restarted?
You, as a developer are the only one who have access to this database, thus it is only your code which will be allowed to change the state or content of this database.
Yes, the data will remain there.
The data will remain there because of your default create method. There is a status code. You can use SQLScout http://www.idescout.com/ to visualize the table and watch its change step by step.
Yes, data will remain in your application when you close the application. When you run the application the database create in the application.
But yes, if the user uninstalls, the application then user will lose the application. On the other hand, if you want to save the data when the application is uninstalled, then it's better to create the database in SDCard.

Categories

Resources