realm-java icon indicating copy to clipboard operation
realm-java copied to clipboard

RealmQuery findAllAsync() not working

Open idok595 opened this issue 9 years ago • 5 comments

realm version: 3.1.4 i am trying to RealmQuery.findAllAsync after creating a realm insatanse,my table is very big arround 10K records + 10-20MB, some times the RealmChangeListener called and sometimes not, on debug mode in 90% of times it called, but in normal mode it dosent called at all.

idok595 avatar May 11 '17 09:05 idok595

You need to store the results as a field variable

Zhuinden avatar May 11 '17 09:05 Zhuinden

Note you need to keep a reference to your RealmResults to avoid it being GC'ed. Most likely in a class variable:

public Foo {
  private RealmResults<Bar> results;

  private baz() {
    results = realm.where(Bar.class).findAllAsync();
    results.addChangeListener(listener);
  }
}

If that is not your problem, you need to provide some code we can look at.

cmelchior avatar May 11 '17 09:05 cmelchior

yes that is my problem, but why?, by the way there is nothing on the documentation about it...

idok595 avatar May 11 '17 09:05 idok595

It is on the website: https://realm.io/docs/java/latest/#notifications But we should probably also make it more clear in the Javadoc.

cmelchior avatar May 11 '17 09:05 cmelchior

Closed by #4631

cmelchior avatar May 11 '17 13:05 cmelchior