(1)这里的异常信息仅仅是android.database.sqlite.SQLiteException: database is locked, 在我研发过程中,还抛出了类似这样的异常信息。该异常是不可以被捕获的。 (2)android.database.sqlite.SQLiteException: database is locked(一些信息)。该异常是可以被捕获的。
Android技术文档提到:A content provider is only required if you need to share data between multiple applications. For example, the contacts data is used by multiple applications and must be stored in a content provider. If you don't need to share data amongst multiple applications you can use a database directly via SQLiteDatabase.
The reason a ContentProvider solves the problem is because it usually uses one singleSQLiteOpenHelperwhich means that there is only one connection to the database and the underlyingSQLiteDatabasetakes care of the locking. You don't need a ContentProvider - just make sure you don't write to the DB using 2 different db connections.
A. ContentProvider能解决此问题的原因是它只用一个单一的SQLiteOpenHelper对象,也就是说在app中仅仅有一个“数据库连接” 连接着数据库并且由SQLiteOpenHelper中的SQLiteDatabase负责维护数据库的锁。
B. 你不需要一个ContentProvider -只要确保不要用2个不同的“数据库连接”去连接数据库就可以了。