I want to set a custom resolution for this scenario: 1- increment an integer field in realmobject in one device in offline mode 2- increment the same integer field in same realmobject in another device in offline mode The default custom resolution is last update wins but in my case I want the increment in both devices take effect on result after going live not last update. I tried this code for test:
Realm realm = Realm.getDefaultInstance();
final RealmResults<Number> results= realm.where(Number.class).findAll();
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
int num = results.get(0).getNumber()+1;
results.get(0).setNumber(num);
}
});
the Number class is like this:
public class Number extends RealmObject {
@PrimaryKey
private String id;
private int number;
public String getId() {
return id;
}
public void increment(){
this.number++;
}
public void setId(String id) {
this.id = id;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
This problem is very crucial to my app. If I can't do this in client side I will not be able to use realm mobile platform which I was get so interested in.
Maybe you can use list of commands for such objects, persist them in offline and sync/merge on going online. Commands can be something like
increment,decrement,multiplyBy2and so on.Documentation says:
So you will always have list of applied commands sorted by date.