Create your account

Already have an account? Login here

Create account

58. Realm Queries

Design + Code an Android App from Scratch

Woah, wait a second..

Scrounge up some loose change to become a pro member, or login to your account to view this lesson.

Alright, join now. Or login to your account if you're already a pro member.

This video talks about realm queries in Android. Get an instance of the RealmObject for your class, call the where method to specify the name of the class or table to fetch results from, the equalTo method to specify conditions on instance variables of the class, find method or its variants to get a list of objects from the realm database that satisfy the given query which returns a RealmResults object. If you use the findAsync method, the query will be executed asynchronously and our RealmResults object will need a registered RealmChangeListener which has a single method called onChange which is called when the results are loaded. To sort results, you can use allObjects and allObjectsSorted variations, to compare values you can use methods such as between, greaterThan, lessThan, greaterThanOrEqualTo and lessThanOrEqualTo, equalTo, notEqualTo method. Use the sum, min, max and average methods to work with numerical results as a collection. To remove objects, begin a transaction and simply call removeFromRealm on a single object or clear on a RealmList or RealmResults object and commit the transaction.

Course Cirriculum