Created
November 9, 2016 14:46
-
-
Save patrickhammond/a6a359f5cad629eec4dd52d85350cd68 to your computer and use it in GitHub Desktop.
Correctly managing realm results that also have an associated change listener.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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