How to delete SQLite database from Android programmatically

前端 未结 12 1611
猫巷女王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:31

    The SQLiteDatabase.deleteDatabase(File file) static method was added in API 16. If you want to write apps that support older devices, how do you do this?

    I tried: file.delete();

    but it messes up SQLiteOpenHelper.

    Thanks.

    NEVER MIND! I later realized you are using Context.deleteDatabase(). The Context one works great and deletes the journal too. Works for me.

    Also, I found I needed to call SQLiteOpenHelp.close() before doing the delete, so that I could then use LoaderManager to recreate it.

提交回复
热议问题