アンドロイドのデフォルトレルムデータベースをクリアするには?私は次のコードを試しましたが、メソッドdeleteRealmFileを解決できません。Androidレルムのデフォルトデータベースクリア
方法1:
try {
Realm.deleteRealmFile(context);
//Realm file has been deleted.
} catch (Exception ex){
ex.printStackTrace();
//No Realm file to remove.
}
私は設定を使用して削除しようとしました。
方法2:
try {
Realm.deleteRealm(realm.getConfiguration());
//Realm file has been deleted.
} catch (Exception ex){
ex.printStackTrace();
//No Realm file to remove.
}
されるが、エラーを与える:説明例外として
java.lang.IllegalStateException: It's not allowed to delete the file associated with an open Realm. Remember to close() all the instances of the Realm before deleting its file.
ように動作します:オープンレルムに関連付けられているファイルを削除することが許可されていません。ファイルを削除する前に、レルムのすべてのインスタンスを閉じる()ことを忘れないでください。 – shekar