Skip to content

Instantly share code, notes, and snippets.

@patrickhammond
Created November 9, 2016 14:46
Show Gist options
  • Save patrickhammond/a6a359f5cad629eec4dd52d85350cd68 to your computer and use it in GitHub Desktop.
Save patrickhammond/a6a359f5cad629eec4dd52d85350cd68 to your computer and use it in GitHub Desktop.
Correctly managing realm results that also have an associated change listener.
private void setupChangeListener() {
RealmResults<Unique> results = realm.where(Something.class).findAll();
handleResults(results);
// I've tried this with the listener as an anonymous inner class and also assigning it to a
// field to ensure there isn't an issue with it being GC'd.
results.addChangeListener(new RealmChangeListener<RealmResults<Something>>() {
@Override
public void onChange(RealmResults<Something> element) {
handleResults(element);
}
});
}
private RealmResults<Something> results;
private void setupChangeListener() {
results = realm.where(Something.class).findAll();
handleResults(results);
results.addChangeListener(new RealmChangeListener<RealmResults<Something>>() {
@Override
public void onChange(RealmResults<Something> element) {
handleResults(element);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment