In this blog:
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
It is one line this.getReadableDatabase();, I don’t understand what it does, but if I remove it from my code it stops working.
/**
* Creates a empty database on the system and rewrites it with your own database.
* */
public void createDataBase() throws IOException{
boolean dbExist = checkDataBase();
if(dbExist){
//do nothing - database already exist
}else{
//By calling this method and empty database will be created into the default system path
//of your application so we are gonna be able to overwrite that database with our database.
this.getReadableDatabase();
try {
copyDataBase();
} catch (IOException e) {
throw new Error("Error copying database");
}
}
}
From the function implementation you can see that this api opens the database by calling getWritableDatabase(). In case it fails due to some reason, it opens the db in a read-only mode.
Here is the implementation of getWritableDatabase()