android – getWritableDatabase()和getReadableDatabase()之间的区别?

前端之家收集整理的这篇文章主要介绍了android – getWritableDatabase()和getReadableDatabase()之间的区别?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用读写数据库没有任何问题.但我无法找出差异.我在互联网上搜索但不太清楚.有人能告诉我区别吗?在哪种情况下我应该使用getWritable Database()或getReadableDatabase()?

@R_502_323@

检查 Reference

公共同步sqliteDatabase getReadableDatabase()

自:API级别1

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()一样,此方法可能需要很长时间才能返回,因此您不应从应用程序主线程(包括ContentProvider.onCreate())调用它.
返回

a database object valid until getWritableDatabase() or close() is called.

抛出
sqliteException如果无法打开数据库

公共同步sqliteDatabase getWritableDatabase()

自:API级别1

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.

数据库升级可能需要很长时间,您不应该从应用程序主线程调用方法,包括从ContentProvider.onCreate().
返回

a read/write database object valid until close() is called

抛出sqliteException如果无法打开数据库进行写入

原文链接:https://www.f2er.com/android/314177.html

猜你在找的Android相关文章