Design + Code an Android App from Scratch
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.