1

かなり頻繁に次の例外が発生しますが、それに対して何をすべきかは完全に確信しています。

java.lang.RuntimeException: An error occured while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:200)
    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
    at java.lang.Thread.run(Thread.java:1019)
Caused by: android.database.sqlite.SQLiteException: error code 5: database is locked
    at android.database.sqlite.SQLiteStatement.native_execute(Native Method)
    at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:61)
    at android.database.sqlite.SQLiteDatabase.delete(SQLiteDatabase.java:1704)
    at azurewing.android.db.provider.NotificationProvider.delete(NotificationProvider.java:80)
    at azurewing.android.db.provider.Provider.delete(Provider.java:87)
    at azurewing.android.db.provider.NotificationProvider.delete(NotificationProvider.java:1)
    at android.content.ContentProvider$Transport.delete(ContentProvider.java:234)
    at android.content.ContentResolver.delete(ContentResolver.java:692)
    at azurewing.android.db.table.NotificationTable.removeAllNotifications(NotificationTable.java:89)
    at azurewing.android.sync.SyncReceiver$1$1.doInBackground(SyncReceiver.java:52)
    at azurewing.android.sync.SyncReceiver$1$1.doInBackground(SyncReceiver.java:1)
    at android.os.AsyncTask$2.call(AsyncTask.java:185)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
    ... 4 more

AsyncTask を介して ContentProvider (ここでは NotificationProvider) にアクセスしています。ContentProvider はもちろんデータベースを使用します。

@Override
public int delete(Uri uri, String selection, String[] selectionArgs)
{
    SQLiteDatabase  db = database.getWritableDatabase();
    int numDeleted = database.delete(NotificationTable.TABLE_NAME, selection, selectionArgs);
    return numDeleted;
}

私はここで何をすべきかについて少し困惑しています。それは明らかにスレッドの問題だと思うので、データベースを取得するたびに、1つのクラスの同期メソッドからそれを行うことを考えています。これは良い考えですか?

4

1 に答える 1

6

また:

  • それらを 1 つのプロバイダに 1 つに統合SQLiteOpenHelperし、値を比較してUriどのロジック セットを通過するかを確認します。

  • provider/ ごとに 1 つSQLiteOpenHelper、または4 つの別個のデータベースを作成します。

  • SQLiteOpenHelper4 つのプロバイダーすべてが共有するシングルトンを用意する

Android の SQLite スレッドは によって管理されSQLiteDatabaseます。SQLiteDatabaseこれが機能するには、すべてのスレッドが共有するのインスタンスが 1 つだけ必要です。を使用している場合SQLiteOpenHelper、これは通常、 のインスタンスを 1 つだけ使用することを意味しSQLiteOpenHelperますSQLiteDatabase

于 2013-09-07T14:17:19.873 に答える