How to check if a DB exists in Android?

后端 未结 4 551
广开言路
广开言路 2021-01-19 15:05

I am using Room API to implement a DB in my Android app. It seems that every time I load my app it tries to create the database again and again. Is there any way to restrict

4条回答
  •  悲&欢浪女
    2021-01-19 15:22

    You are using db that is, in fact, a file. You can check, if it exists, this method could be helpful:

    private static boolean doesDatabaseExist(Context context, String dbName) {
        File dbFile = context.getDatabasePath(dbName);
        return dbFile.exists();
    }
    

提交回复
热议问题