Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear Room database on start in development environment

For development purpose, is there a way to automatically empty all Room data when I rebuild and restart the program? The way I can think of right now is to call some kind of removeAll at the start of the program.

like image 795
Jack Guo Avatar asked Oct 28 '25 17:10

Jack Guo


1 Answers

You can simply use RoomDatabase#clearAllTables();

Sample usage:

if (BuildConfig.DEBUG) {
    database.clearAllTables();
}
like image 174
Bertram Gilfoyle Avatar answered Oct 31 '25 08:10

Bertram Gilfoyle