Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query if Android database exists!

I have created a database for my android app which contains static data and does not require update/delete functionality thus when the app starts, I want to check if the db exists and if not then execute my dbAdapter class. I know its a simple if statement but I was just wondering the most efficient way to query whether the db exists.

Cheers

like image 223
Ally Avatar asked Aug 02 '10 09:08

Ally


1 Answers

I'd rather check the existence of the file directly:

private static boolean doesDatabaseExist(Context context, String dbName) {     File dbFile = context.getDatabasePath(dbName);     return dbFile.exists(); } 
like image 147
rds Avatar answered Sep 28 '22 05:09

rds