Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete SQLite database from Android programmatically

Tags:

android

sqlite

Once you have your Context and know the name of the database, use:

context.deleteDatabase(DATABASE_NAME);

When this line gets run, the database should be deleted.


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.


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

Try:

this.deleteDatabase(path); 

or

context.deleteDatabase(path);

context.deleteDatabase("database_name.db");

This might help someone. You have to mention the extension otherwise, it will not work.


Also from Eclipse you can use DDMS which makes it really easy.

Just make sure your emulator is running, and then switch to DDMS perspective in Eclipse. You'll have full access to the File Explorer which will allow you to go in and easily delete the entire database.