I've got a Realm results change listener that isn't being triggered, here's the code:
final RealmResults<LogEntry> entries = realm.where(LogEntry.class).findAll();
entries.addChangeListener(new RealmChangeListener<RealmResults<LogEntry>>() {
@Override
public void onChange(RealmResults<LogEntry> results) {
Log.v("Testing", "The size is: " + results.size());
}
});
There is definitely new stuff being added, I have a log on the realm insertion printing out the new size of the table, yet for some reason the change listener does nothing? Am I missing something here, it seems identical to the docs.
You need to keep a class reference to entries
to prevent it from being GC'ed:
public MyClass {
private RealmResults<LogEntry> entries;
public void myMethod() {
entries = realm.where(LogEntry.class).findAll();
entries.addChangeListener(new RealmChangeListener<RealmResults<LogEntry>>() {
@Override
public void onChange(RealmResults<LogEntry> results) {
Log.v("Testing", "The size is: " + results.size());
}
});
}
}
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