How to check if a DB exists in Android?

后端 未结 4 553
广开言路
广开言路 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:21

    Try this

    if (!db.exists()) {
        // Database does not exist so copy it from assets here
        Log.i("Database", "Not Found");
    } else {
        Log.i("Database", "Found");
    }
    

提交回复
热议问题