I have preloaded sqlite database located in assets, which is copied to default database location after app first installation. I'd like to do this procedure on each app update. I don't need to keep any user data from existing database.
How to delete old database file, when app is being updated?
These are actually two questions:
You could save a variable with the last version code in a Shared Preferences. After each start of the application you check your current code with the saved code. If they don't match, it was an update and you execute some code.
If the database is closed, you can simply delete the file. Use Context.getDatabasePath(String) to find the location of the file, and File.delete() for deleting it. Make sure no process is accessing the database file. If so, you might need to use the File.deleteOnExit() and force a restart of the application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With