所以我有以下问题:
if (!realm.isClosed()){
Log.d("PROVIDER realm not clsd", "closing now");
realm.executeTransaction((t)->realm.close());
}
这会引发异常。这是:
D/PROVIDER realm not clsd: closing now
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start receiver This Realm instance has already been closed, making it unusable.
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3047)
现在,当"Realm instance has already been closed"
?
realm.isClosed()==false
的
答案 0 :(得分:3)
在您检查realm.isClosed()
时,它确实没有关闭。但是,您已经打开了一个事务,为了完成该事务,仍然需要打开realm实例。问题是,您在事务中关闭此实例。 简单解决方案:从交易中删除realm.close()
,它不需要在一个。