9

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.

5
  • do you want to insert it in separate column ? if it is then you can set currentTimeStamp value in object of Class and then insert Commented Sep 23, 2015 at 9:22
  • 1
    Yes i can but it will be very risky - as i have to do it for every insert and update manually. Commented Sep 23, 2015 at 9:29
  • can you use update query at last Commented Sep 23, 2015 at 9:30
  • I am using realm. i cannot get your suggestion. Commented Sep 23, 2015 at 9:51
  • please see my answer if it can help Commented Sep 23, 2015 at 9:53

2 Answers 2

2

use this

    realm.beginTransaction();
    RealmResults<ModelClass> hallos =     realm.where(ModelClass.class).equalTo('name', 'hello').findAll();
    for (ModelClass object : hallos) {
        object.setTimeStamp(timestamp);
    }
    realm.commitTransaction();
1
  • 6
    I want to automate this system because i don't want to do it every time i insert/update any row. Commented Sep 28, 2015 at 6:45
0

You can use RealmChangeListeners to handle all changes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.