6

How can I delete the database from the application?

4 Answers 4

9

Did you check deleteDatabase() method available in Android?

Sign up to request clarification or add additional context in comments.

Comments

3
File dbFile = getDatabasePath("your_db_file_name");
boolean deleted = dbFile.delete();

4 Comments

If your phone is not rooted and if your database is inside your application folder(data/data) i doubt whether this can delete it.
You may delete it inside an application in which you created it.
I've tried that approach on my database and it refuses to be deleted. I don't use getDatabasePath() as I create the database on the sd-card, but File.delete() always returns false. Is there anything else I need to call on the database itself other than close() to allow the file to be deleted?
DO NOT simply delete the file. Look at SQLiteDatabase#deleteDatabase and notice how it also deletes metadata files associated with the db: grepcode.com/file/repository.grepcode.com/java/ext/…
1

Old post, but I think its worth adding this in case this feature wasn't available back then. I use Context. For example, when your in MainActivity

this.deleteDatabase("mydata.db");

or when you have a context handle elsewhere

context.deleteDatabase("mydata.db");

Comments

0

Do you need to delete the actual db file or is it enough to just DROP the tables? I'd imagine the end result is the same and dropping the tables could be easier.

1 Comment

i want to delete the actual db file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.