Difference between getWritableDatabase() and getReadableDatabase()?

后端 未结 4 560
悲哀的现实
悲哀的现实 2020-12-29 14:11

I use reading and writing to the database without any problems . But I can not find out the difference. I searched on Internet but it \'s not quite clear. Can anyone tell me

4条回答
  •  醉酒成梦
    2020-12-29 14:47

    The main difference is -

    getReadbleDatabase() -

    • Create and/or open a database. This will be the same object returned by getWritableDatabase() unless some problem, such as a full disk, requires the database to be opened read-only. In that case, a read-only database object will be returned. If the problem is fixed, a future call to getWritableDatabase() may succeed, in which case the read-only database object will be closed and the read/write object will be returned in the future.

    getWritableDatabase() -

    • Create and/or open a database that will be used for reading and writing. The first time this is called, the database will be opened and onCreate(SQLiteDatabase), onUpgrade(SQLiteDatabase, int, int) and/or onOpen(SQLiteDatabase) will be called. Once opened successfully, the database is cached, so you can call this method every time you need to write to the database. (Make sure to call close() when you no longer need the database.) Errors such as bad permissions or a full disk may cause this method to fail, but future attempts may succeed if the problem is fixed.

提交回复
热议问题