I use an sqflite database in my app. The database is filled with entries by the users. It is essential that the database is unchanged when I deliver a new app version.
When I deploy a new version of the app as apk to my real phone the database is deleted. Is there a way to protect the database during update?
I wonder if it is the method how I deploy the new app version? I use "flutter install". Maybe the uninstall method removes everything from the app including the database and creates a fresh app directory!?
flutter install deletes app and database. The solution is to use streamed install. Instead of flutter install, run this: adb install build/app/outputs/flutter-apk/app.apk. This will update the app and leave the database intact.
You must have sdk platform-tools installed and an environment variable pointing to the platform-tools.
You can get the contents of old database and store it in temporary database and save all the old content in new database and after successful insert delete temporary database.
In short following pseudo code may help:
tempdb.data = getOldDatabaseContent
newDatabase.data = tempdb.data
delete(tempdb)
After switching to a room database I deleted the SQLite-Helper Class. But if I install my app the old database is still created on my smartphone.
I opened the the device file explorer and found under my project-folder
/databases with the following databases
local.db which is my old database with date of 1970-01-19 and 2.5 MBytes
local_db which is the new room database
local_db-shm and local_db-wal whhich seem to be some room data
Even if I uninstall the app and reinstall it the local.db appears again. Deleting it does not help too.
But I think that I have deleted all the old SQLiteHelper Code. So does anyone know, where I might find the key to getting rid of the old database?
If the manifest (AndroidMainfest.xml) has android:allowBackup="true", this could result in the data being restored automatically by the backup manager. From your description of the issue this could well be the cause.
Try changing to use android:allowBackup="false", uninstalling the App and then re-installing.
I am a beginner in android programming, I created an android app which uses an exist DB with DBFlow. At first time I inserted a temp data to database so I can test the app. When I finished building the app I inserted real data and copied the new database -which is similar to the old one except for the real data- to assets folder but I did not find the new data.
How can I reset the database or change the data.
After changing database you must remove previous version of app from your device and then install the app again. This should solve your problem.
I developed and install an android application which create a sqlite database.
If I uninstall this app the database will be automatically dropped?
The database is a file in private storage ( /data/data/{package.name}/databases/db.file )
when you uninstall an app the /data/data/{package.name}/ is deleted, either the user associated to the app is.
YES....
After create Database it will be located at data/data/YourPackage/mydatabase.db.
when you install application on Emulator or Phone then it will be visible in File Explorer.
This mydatabase.db file will be deleted when you uninstall your application but if you reinstall this application then this database file again created and will be available in your private folder.
Edit
Suppose you want to store some value in Database(SQLite), For this you need to create one java class like MySQLiteHelper and then you can simply write your value in database.
If you uninstall you application then your value and database will be deleted but if you again reinstall your application then your database again created but previous value will be lost.
I think so, database will be dropped with all files in your app's private folder :)
Thanks for previous replies,
is it possible to delete the stored content from sqlite once re-install the application. I am storing data in database, once i re-install the same app again, the previous data still stores in sqlite. i want to delete the stored content while re install the app. i am not sure about this.
This seems like a hack and maybe not the actual answer, but can you -- with each new version of your app -- increment an identifier (from 10 to 11) in the code and then check against a stored preferences containing that identifier. If you have a constant in your code that is higher than the identifier stored on the previous device, then you can clear the database to whatever you think its state should be. Then with each new released version of the app you increment this number..
Edit: In API level 9 and higher, you can -- whenever your app starts up -- write the date in which the app was installed (see here for an explanation on how to find the install date). If you check that it was installed after the date which is written, kill the data!
Thanks for all replies,
I maintain the Version code for all the builds, once i re-install the application, i check the version, if i found the version changes, i simply remove the DB. this case only applicable for overriding the install of APk(ie without un-installing the application). When we made a uninstall, the internal data and sqlite for the application ill automatically deleted.
sqlite databases are stored as files on your file system, to delete the data. You just need to delete the file.
What you'd want to do is setup some way of detecting if the app is being run for the first time, if this is the first time the app has been run then check the database exists, if it does delete it. Then recreate the database as empty.
Or you could go through and remove all the data in each table/drop each table in the database on the first run if the database exists.
Read here : Detect Android app upgrade and set Application class boolean for show/hide of EULA
Create a UpgradeBroadcastReceiver of your own that will run the delete instructions you want and register it in your manifest file.
When you delete the app, then the database should be deleted too. Unless you go to some trouble to keep it. If you simply update the app, then the data should be kept. If you need to delete the data upon reinstall, try this:
Every time you start an Activity, call PackageManager.getPackageInfo() and check lastUpdateTime. Compare it with a time stamp that you store in the database or a shared preference. If lastUpdateTime is newer, delete the your database.
application SharedPreferance is deleted on un-installing the app, so save a boolean to determine if the application is running for the first time or not.