3

I have a flutter app where I use a sqflite DB storage. I create a DB as pointed in the sqflite example - I use getDatabasesPath() as a relative path to the app and then var db = await openDatabase(path_to_db_file);. Everything works fine, I can create tables, work with data and so on.

I face a problem when I uninstall the app. While still in development I need to add more tables, purge data, change column names, etc. I want after I uninstall the app, to delete all the files associated with it and on the next install (debug session) start fresh. This works on some devices. There are cases where after uninstalling the app some files remain. The DB file remains. And when I install the new version with expected DB changes, they don't work against the database file that has remained undeleted.

I would like to ask is there a mechanism to explicitly tell android to delete everything associated with that app upon uninstalling it?

Hamed
  • 5,867
  • 4
  • 32
  • 56
  • You might want to check with your database version. If you make changes (table changes, etc), you might want to update your database version. See [sqflite database migration](https://github.com/tekartik/sqflite/blob/master/sqflite/doc/opening_db.md#migration) – adadion Mar 24 '20 at 09:21
  • Thanks for answering! I don't keep track of the DB changes (schema). The way I introduce changes (since the schema is simple) is I delete the DB and then if the file doesn't exist upon first start, I create it with the new SQL query. The problem comes when the file IS there for some reason. – Borislav Nanovski Mar 24 '20 at 09:27
  • Unfortunately, on some devices, when a user uninstall app, some are completely delete the app and its data, but some are only removing the app itself while the data (including local sqlite database) still remain. I'm personally when doing testing and don't want to use db versioning, I'll clear cache and data for my app, then finally doing the uninstall. – adadion Mar 24 '20 at 09:34
  • Yes :/ And the device that causes problem is a Honor phone. I do "delete cache", "delete data", "uninstall" and then after installing the APK - still the db file is there! – Borislav Nanovski Mar 24 '20 at 09:38

1 Answers1

9

Some android phones auto backup data even when you uninstalled app, the data still comes back. This is what i've done in my app:

in AndroidManifest.xml:

<application
    android:name=".Application"
    android:allowBackup="false"
    android:fullBackupOnly="false"

above 2 backup properties to false

Jim
  • 6,928
  • 1
  • 7
  • 18