Android-app: Old database still exists after switching to room database - android

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.

Related

How to protect sqflite database when updating flutter app

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)

What is the best approach to backup Room database?

Actually I have more than a question. If I uninstall an app, the room database also removed. I debugged and checked using File(getDatabasePath("MyInfoDatabase.db").absolutePath).exists() before instantiating a room database. Let's say my app crashed and I uninstalled it and then reinstall the app. So it is not possible to get the old room data.
Room.databaseBuilder(appContext, AppDatabase.class, "Sample.db")
.createFromFile(File("mypath"))
.build()
If I am not wrong, then I can copy and save the database to a directory and get the old databack while reinstalling using the above method. Is this the right approach? In this approach getExternalStoragePublicDirectory is deprecated now. Should I use MediaStore api for database backup? On the other hand here, it says that room data exists even after uninstalling. Is the room database exists even after uninstalling an app? AFAIK it doesn't exists.

Change or reset prepackaged database in DBFlow

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.

SQLite data disappears after being updated

I've created an empty table in a sqlite database, DB, via a database adapter.
Since I have a lot of data (10,000+ rows) to be inserted and I don't want to do it in the activities so I pull the sqlite database out of data/data/package-name/databases and inserted the rows via sqlite browser software. I then reinserted/push the updated DB it back into the eclipse DDMS and all was fine at first.
The DB has an inflated size of 800kb from the original 22kb.
But after running the emulator again, I noticed that the DB shrunk back to 22kb and upon pulling it out and inspecting it, the rows I inserted is no longer there.
Strange enough, the DB journal file in the same folder is now inflated to 800kb, but I can not open that file (sqlite browser says the file is either corrupt or encrypted but not a valid Sqlite file). Can someone explain what happened?
Did you commit changes after updating database? Also check if database is not dropped when Eclipse uninstall old version of the application before new one is deployed on target.

Delate database while reinstallation android

Hello
In my android application when the user reinstall the app again i would like to delete the existing database and create a fresh new one.
How could i know that the user is reinstalling the app or is quering for the updates request.
How could i delete a file in raw folder?
Please share your valuable suggestions.
Thanks in advance:)
Hello In my android application when the user reinstall the app again i would like to delete the existing database and create a fresh new one.
If by "reinstall", you mean "uninstall and reinstall", your existing database will be deleted during the uninstall process, assuming it resides in the normal database location (i.e., not on external storage).
How could i know that the user is reinstalling the app
You don't.
How could i delete a file in raw folder?
In Android? You don't. Resources cannot be modified or removed at runtime.
Reinstalling application deletes all data for the application. If you mean reinstalling is upgrading then you can observe the new version number in the SQLiteOpenHelper.onUpgrade() method.
To delete the database file, it is explained here (Database Delete Android).

Categories

Resources