Archives: Android

Android Retrofit – POST Request Example

Retrofit Android Example to Consume HTTP POST RESTful Web Service Request using Retrofit 2 library in Android and Java

build.gradle [Module]

RetroClient.java

User.java

RetroService.java

MainActivity.java



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.