I have an Android app that uses GreenDao for persistence.
I am under the impression that uninstalling the app from a device should remove any data files under the path /data/data/[package name]/databases, which is where GreenDao stores its data by default (Where is my database file created)
Given I have closed my app to ensure it is not running and uninstall the app, when I reinstall the app and run it, then I would expect there to be no data from previous sessions stored.
However, the specific user data I have stored in this previous session remains available when I perform a getRowById request to the relevant UserDao after the clean install.
Why does this data persist after uninstall?
Check android:allowBackup value in android manifest, if the value is set to true then android will backup the db, and will persist it after uninstall.
Related
I'm using Flutter-SQLite-Dart to develop a mobile application that has basic functionality just as Quiz application. I store questions and answers to my local database, when cache is cleared then the stored data gets erased. I need to save those data without getting lost. What methodology to use for achieving a solution for this issue?
For Android, you have two options in App info - clear data(clear storage) and clear cache.
By default, SQLite DB is saved in the internal app data directory, so when you clear the cache(app cache directory), all your DB data are still alive. But if you clear data(clear storage) you remove your DB + cache + other data.
If you want to keep DB after clear data(clear storage) or uninstalling the application, you have some options:
Back up user data with Auto Backup
Auto Backup for Apps automatically backs up a user's data from apps that target and run on Android 6.0 (API level 23) or higher. Android preserves app data by uploading it to the user's Google Drive—where it's protected by the user's Google account credentials. The amount of data is limited to 25MB per user of your app. There's no charge for storing backup data. Your app can customize the backup process
You can try to change the DB saved directory. For example, save it to Documents or so.
Use firebase_database
All those options have pros and cons...
And pay attention please, when the user will try to clear app data, Android will show an alert dialog with the next information:
All this app's data will be deleted permanently. This includes all files, settings, accounts, databases, etc.
I am developing an app that uses the ROOM database implemetation. The database is simple with only 2 tables.
I am trying to simulate what will happen with the persisted data when the app is uninstalled and reinstalled, hoping that it will be included in the default google app backup.
This is where I am confused - Within Android Studio I start a debugging session that re installs the App after Uninstall - I can add data to database running the app in a debug session or normally from the device. The database survives a restart etc of the phone and updated data remains.
BUT when I uninstall and reinstall using a debugging session I have a version of the database come across somehow from android studio - one from earlier debugging - All of the changes since last reinstall are lost.
Where is this database copy coming from and more importantly how can I make sure that my db changes survive an app uninstall and reinstall.
I am using the path returned by getdatabasepath()
Any help or pointers appreciated on approaches to ensure this dataset survives app reinstall.
I am building the DB as follows
return Room.databaseBuilder(context,
MyDb.class,
Constants.DB_NAME).allowMainThreadQueries().build();
And getting an instance of the DB like so
MyDB = DigiDocketDB.getInstance(MainActivity.this);
Cheers,
Courtney.
I know that one instance where an App's SQLite file may be removed from the System is when the user uninstall the Application. Apart from this situation, under what circumstance(s) will the SQLite file get lost or be destroyed in the Android System?
Again, under what circumstance will the SQLite database file loose all it's content even if the App is not uninstalled?
Will there be an instance where the Android System does this?
Settings -> App -> Data -> Clear Data would also delete the SQL. Also rooted phone can do whatever he likes with the SQLite files.
There is no way that the Android system will erase or remove your file. Database files are stored, along with other app data, under {package_name}/data/data folder so no one except your app can touch it (ignore rooted devices).
Only the following can happen:
1. your code cleared/corrupted the db file
2. user has cleared app data from device settings
I have an App on Playstore. The app is named Credit Flow.It is used to track income and expenses of an individual.
I use local Sqlite Db to save all the transactions(they are not saved on any server).
I am new to pushing apk updates. My question here is that if I upload a new Apk on playstore will it erase the existing user's Local Db?
If so how can I prevent that?
My question here is that if I upload a new Apk on playstore will it erase the existing user's Local Db?
No. Assuming you are using your database in the default directory, your database will remain untouched.
The database will only be removed if the user uninstalls your application, or goes into the app settings and clears your app's data.
Also note that onUpgrade() will not be called on your SQLiteOpenHelper. That method is only called when you increment the version number passed into the SQLiteOpenHelper constructor.
No, the data is preserved. But ensure your using the same package name. Updates do not alter sharedpreferences or databases or other files that generated in run time
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.