Reputation: 1054
So I have the following problem:
if (!realm.isClosed()){
Log.d("PROVIDER realm not clsd", "closing now");
realm.executeTransaction((t)->realm.close());
}
and this throws exception. Here it is:
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)
Now how the hell is "Realm instance has already been closed"
, when realm.isClosed()==false
?
Upvotes: 1
Views: 83
Reputation: 3997
At the moment that you check realm.isClosed()
it is not closed indeed. However, you have opened a transaction which, in order to complete, still needs that realm instance to be open. The problem is, you're closing this instance inside the transaction. Simple solution: remove realm.close()
from inside the transaction, it doesn't need to be in one.
Upvotes: 3