Tutorial by Examples

Add the following dependency to your project level build.gradle file. dependencies { classpath "io.realm:realm-gradle-plugin:3.1.2" } Add the following right at the top of your app level build.gradle file. apply plugin: 'realm-android' Complete a gradle sync and you now have ...
Realm models must extend the RealmObject base class, they define the schema of the underlying database. Supported field types are boolean, byte, short, int, long, float, double, String, Date, byte[], links to other RealmObjects, and RealmList<T extends RealmModel>. public class Person extend...
Realm currently does not support storing a list of primitives. It is on their todo list (GitHub issue #575), but for the meantime, here is a workaround. Create a new class for your primitive type, this uses Integer, but change it for whatever you want to store. public class RealmInteger extends Re...
try (Realm realm = Realm.getDefaultInstance()) { realm.executeTransaction(new Realm.Transaction() { @Override public void execute(Realm realm) { //whatever Transaction that has to be done } }); //No need to close realm in try-wit...
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 ...
Every synchronous query method (such as findAll() or findAllSorted()) has an asynchronous counterpart (findAllAsync() / findAllSortedAsync()). Asynchronous queries offload the evaluation of the RealmResults to another thread. In order to receive these results on the current thread, the current thre...
For queries, Realm provides the realmResults.asObservable() method. Observing results is only possible on looper threads (typically the UI thread). For this to work, your configuration must contain the following realmConfiguration = new RealmConfiguration.Builder(context) // ...
Setting up an instance To use Realm you first need to obtain an instance of it. Each Realm instance maps to a file on disk. The most basic way to get an instance is as follows: // Create configuration RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(context).build(); // O...

Page 1 of 1