5

My app uses the SyncAdapter pattern, holding user credentials using the AccountManager and a ContentProvider to store data in a db.

When the account gets removed I can remove the db using the approach explained in this question. The db gets removed by doing:

boolean deleted = mContext.deleteDatabase(DatabaseHelper.DATABASE_NAME);

This works fine but when I do the login again everything is still there. It feels like the ContentProvider doesn't know that the db has been removed.

In this answer, inazaruk says:

You need to make sure you've killed the process that hosts ContentProvider that uses that specific database file. And only than delete it.

Killing the process to clear a db doesn't feel right.

Is there a better thing to do?

4

1 に答える 1

2

私がそれをしなければならなかった場合、私は次の方法でそれを試します:

Uriを使用して挿入または削除するときに、Uriデータベースの削除をトリガーするものをいくつか追加しますContentProvider。削除するときは、 へのすべての参照もクリアしますSQLiteDatabase。それを介して古いデータベース ファイルに引き続きアクセスできる可能性があるためです (Linux でファイルを削除し、そのファイルを開いたままにしておくと、引き続き使用できます。道)。

削除を内部に配置するContentProviderことで、データベース接続を閉じて、データベース ファイルを再作成する必要があることがわかっている方法で削除状態を追跡できるはずです。

ContentProvidersアプリを強制終了しない限り終了しないでください。おそらく同じインスタンスが実行されており、上記のように古いファイルへの参照が存在する可能性があります

于 2012-08-08T17:16:29.673 に答える