How to delete a database in an Android application

How can I remove the database from the application?

+6
android database sqlite
source share
4 answers

Have you checked the deleteDatabase() method available in Android?

+9
source share
 File dbFile = getDatabasePath("your_db_file_name"); boolean deleted = dbFile.delete(); 
+3
source share

An old post, but I think it’s worth adding this if this feature was not available 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"); 
+1
source share

Do you need to delete the actual db file, or is just DROP enough for tables? I would suggest that the end result is the same, and dumping the tables might be easier.

0
source share

All Articles