The title says it all. I've done some searching but haven't found anything concrete.
Do I need to call realm.close after doing realm.executeTransactionAsync or does the async transaction handle that?
Thank you
EDIT: Per EpidPandaForce, executeTransactionAsync closes the background realm instance when complete.
But what is the proper way to close the realm instance if executeTransactionAsync is called from the UI thread? In the transactions onSuccess/onFailure?
You seem like you're looking for the following scenario.
public void doWrite(MyObject obj) {
Realm realm = Realm.getDefaultInstance();
realm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm bgRealm) {
bgRealm.insert(obj); // assuming obj is unmanaged
}
}, new Realm.Transaction.OnSuccess() {
@Override
public void onSuccess() {
realm.close();
}
}, new Realm.Transaction.OnError() {
@Override
public void onError(Throwable error) {
realm.close();
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With