我覆盖了applybatch(),并执行了一些插入操作,但有时会报告错误,如下所示。更重要的是,我无法重现它......
提前致谢。
android.database.sqlite.SQLiteException
android.database.sqlite.SQLiteConnection.nativeExecute 【count : 75】 【user_count : 60/58414】
android.database.sqlite.SQLiteException: cannot rollback - no transaction is active (code 1)
at android.database.sqlite.SQLiteConnection.nativeExecute(Native Method)
at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:548)
at android.database.sqlite.SQLiteSession.endTransactionUnchecked(SQLiteSession.java:439)
at android.database.sqlite.SQLiteSession.endTransaction(SQLiteSession.java:401)
at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:522)
at com.example.home.launcher.LauncherProvider.applyBatch(LauncherProvider.java:290)
at android.content.ContentProvider$Transport.applyBatch(ContentProvider.java:222)
at android.content.ContentProviderClient.applyBatch(ContentProviderClient.java:225)
at android.content.ContentResolver.applyBatch(ContentResolver.java:947)
at com.example.home.launcher.k.run(LauncherModel.java:221)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.os.HandlerThread.run(HandlerThread.java:60)
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
ContentProviderResult[] result;
synchronized (mLock) {
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.beginTransaction();
try {
result = super.applyBatch(operations);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
return result;
}