realm/realm-android-adapters

cannot updateData when Realm is closed

YusukeIwaki opened this issue · 2 comments

RealmRecyclerViewAdapter#updateData internally calls removeListener(adapterData) without cheking if adapterData is valid or not, which sometimes causes

java.lang.IllegalStateException: This Realm instance has already been closed, making it unusable.

adapterData sometimes suddenly becomes invalid when Realm is closed for some reason... (GC? OOM killer?)
So I tried to work around it with the logic like below:

public void onResume() {
  super.onResume();

  // update data if it is already invalid for some reason.
  if (!mAdapter.getData().isValid) {
    if (mRealm == null || mRealm.isClosed()) mRealm = Realm.getDefaultInstance();
    mAdapter.updateData(mRealm.where(XX.class).... .findAll()
  }
}

but not working... java.lang.IllegalStateException: This Realm instance has already been closed, making it unusable.

I want RealmRecyclerViewAdapter#updateData not to call removeListener if adapterData is invalid...

Version of Realm and tooling

realm: 1.1.0
realm-android-adapters: 1.3.0

Hi @YusukeIwaki
Yes that sounds like a bug that should be fixed.

fixed in #71