Android Realm Sorted queries

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

In order to sort a query, instead of using findAll(), you should use findAllSorted().

RealmResults<SomeObject> results = realm.where(SomeObject.class)
                                            .findAllSorted("sortField", Sort.ASCENDING);

Note:

sort() returns a completely new RealmResults that is sorted, but an update to this RealmResults will reset it. If you use sort(), you should always re-sort it in your RealmChangeListener, remove the RealmChangeListener from the previous RealmResults and add it to the returned new RealmResults. Using sort() on a RealmResults returned by an async query that is not yet loaded will fail.

findAllSorted() will always return the results sorted by the field, even if it gets updated. It is recommended to use findAllSorted().



Got any Android Question?