realm-java: RealmChangeListener never called inside RealmResults
Hi, i use realm for a lot of time but today i want to try use new feature called “Async query”. I would be grateful for tell me what I’m doing wrong.
realm version: compile ‘io.realm:realm-android:0.86.0’ empty main activity snippet:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
RealmResults< MyRealmObject> realmResults = Realm.getInstance(this).where(MyRealmObject.class).findAllAsync();
realmResults.addChangeListener(new RealmChangeListener() {
@Override
public void onChange() {
System.out.println("Never called...");
}
});
}
If i attached debbuger it stay on notifyChangeListeners and listener is not called because “this.currentTableViewVersion != version”. RealmQuery is loaded because after few moment i have acces to data inside list.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 18 (7 by maintainers)
You need to keep a strong reference to the RealmResults otherwise it’ll be eaten alive by the GC
classpath “io.realm:realm-gradle-plugin:3.1.4”
Called in 80% of cases. Obviously there is a race of streams. If it manages to load before subscribing, it is not called.