How to delete SQLite database from Android programmatically

前端 未结 12 1635
猫巷女王i
猫巷女王i 2020-11-27 10:41

I would like to delete the database file from the Android file system programatically? Can I have a shell script launch adb which in turns runs a

12条回答
  •  难免孤独
    2020-11-27 11:35

    context.deleteDatabase(DATABASE_NAME); will delete the database only if all the connections are closed. If you are maintaining singleton instance for handling your database helper - it is easy to close the opened Connection.

    Incase the databasehelper is used in multiple place by instantiating directly, the deleteDatabase + killProcess will do the job even if some connections are open. This can be used if the application scenario doesn't have any issues in restarting the app.

提交回复
热议问题