Archives: Realm

Android Realm – Insert Object Query

Realm Create Object Example in Android and Java – Realm Database

To insert multiple objects, use insert or insertOrUpdate method

Android Realm – Transaction Management

Realm Transaction Management Example in Android and Java – Realm Database

— Unlike read operations, write operations in Realm must be wrapped in transactions.
— At the end of a write operation, you can either commit the transaction or cancel it.

Transaction Block

Instead of manually keeping track of beginTransaction, commitTransaction, and cancelTransaction, you can use the executeTransaction method, which will automatically handle begin, commit, and cancel if an error happens.

Asynchronous Transaction

Since transactions are blocked by other transactions, you might want to write on a background thread to avoid blocking the UI thread. By using an asynchronous transaction, Realm will run that transaction on a background thread.

Android Realm – Database Configuration

Realm Database Configuration Example in Android and Java

— A Realm is an instance of a Realm Mobile Database container.
— Default Realm configuration uses the Realm file “default.realm” located in Context.getFilesDir().
— To use another configuration, you would create a new RealmConfiguration object.
— The RealmConfiguration can be saved as a default configuration.
— Setting a default configuration in your custom Application class makes it available in rest of your code.