How to delete SQLite database from Android programmatically


Question

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 shell script in the Android space to do the database deletion? Can I get this done from within a JUnit test case (with a system() call)?

How do I delete an entire database in Android? I need to make the whole thing go away so I can test database creation. I can drop tables, but that's not enough. This is in the emulator, not on a phone.

1
148
11/1/2014 8:56:29 PM

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.

401
11/1/2014 8:56:43 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon