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
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.
context.deleteDatabase("database_name.db");
This might help someone. You have to mention the extension otherwise, it will not work.
From Application Manager, you can delete whole application with data. Or just data by it self. This includes database.
Navigate to Settings. You can get to the settings menu either in your apps menu or, on most phones, by pulling down the notification drawer and tapping a button there.
Select the Apps submenu. On some phones this menu will have a slightly different name such as Application Manager.
Swipe right to the All apps list. Ignore the lists of Running and Downloaded apps. You want the All apps list.
Select the app you wish to disable. A properties screen appears with a button for Force Stop on the upper left and another for either Disable or Uninstall updates on the upper right side.
Delete data.
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.
It's easy just type from your shell:
adb shell
cd /data/data
cd <your.application.java.package>
cd databases
su rm <your db name>.db
you can create a file object of current database path and then delete it as we delete file from folder
File data = Environment.getDataDirectory();
String currentDBPath = "/data/com.example.demo/databases/" + DATABASE_NAME;
File currentDB = new File(data, currentDBPath);
boolean deleted = SQLiteDatabase.deleteDatabase(currentDB);