Sneak Peek: what’s going to be new in Realm-Java 2.4.0 (or 3.0.0?)

“Results” integration (#3834) was merged

  • BREAKING CHANGE: realmResults.distinct() now returns a new RealmResults, instead of distinct in place.
  • BREAKING CHANGE: RealmChangeListeners added to RealmObject are now also called when the object becomes invalidated (deleted)
  • BREAKING CHANGE: simple ascending for-loops in the following format no longer work inside transactions (if the modification changes the evaluated result set).
RealmResults<MyObject> realmResults = realm.where(MyObject.class)
.equalTo("f", true)
.findAll();
for(int i = 0; i < realmResults.size(); i++) {
MyObject obj = realmResults.get(i);
obj.setF(false); // modifies the RealmResults!
...
for(MyObject obj: realmResults) {    
...
for(int i = realmResults.size()-1; i >= 0; i--) {    
MyObject obj = realmResults.get(i);
...

Wait, but why?

RealmResults<MyObject> res = realm.where(MyObject.class)
.findAll();
OrderedRealmCollection<MyObject> snapshot = res.createSnapshot();for(int i = 0; i < snapshot.size(); i++) {
MyObject obj = snapshot.get(i);
...
for(MyObject obj: realmResults) { // uses snapshot
...
  • beginTransaction() could trigger the RealmResults listeners if there are changes, because beginTransaction() bumps the Realm version — but some will be suppressable (#4225) in order to support drag and drop.
  • RealmResults itself doesn’t use snapshot at all (however the iterator does).
  • CHANGE: Local commit triggers Realm global listener and RealmObject listener on current thread immediately instead of in the next event loop.

Okay, so what’s the benefit?

RealmList.addChangeListener() will now work (#4216)

Link sorts (#672) are now available!

RealmResults<Person> persons = realm.where(Person.class)
.findAllSorted("parent.name");

Fine-grained notifications (#4191) are merged!

RecyclerView animations! (#83)

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store