Syed Hassan
Syed Hassan

Reputation: 438

how to set current timestamp for every insert and update row in realm android

I want to synchronize the android application with server. In Server i have maintained last update date through trigger as it uses SQL server but my android application uses Realm so how can i set current date time in a field whenever any row is inserted or updated. Any suggestion would be highly appreciated.

Upvotes: 9

Views: 2565

Answers (2)

Alex T.
Alex T.

Reputation: 29

You can use RealmChangeListeners to handle all changes

Upvotes: 0

Ashish Agrawal
Ashish Agrawal

Reputation: 1977

use this

    realm.beginTransaction();
    RealmResults<ModelClass> hallos =     realm.where(ModelClass.class).equalTo('name', 'hello').findAll();
    for (ModelClass object : hallos) {
        object.setTimeStamp(timestamp);
    }
    realm.commitTransaction();

Upvotes: 2

Related Questions