use of io.realm.examples.objectserver.model.CRDTCounter in project realm-java by realm.
the class CounterActivity method onStart.
@Override
protected void onStart() {
super.onStart();
user = SyncUser.currentUser();
if (user != null) {
// Create a RealmConfiguration for our user
SyncConfiguration config = new SyncConfiguration.Builder(user, REALM_URL).initialData(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
realm.createObject(CRDTCounter.class, 1);
}
}).build();
// This will automatically sync all changes in the background for as long as the Realm is open
realm = Realm.getInstance(config);
counter = realm.where(CRDTCounter.class).findFirstAsync();
counter.addChangeListener(new RealmChangeListener<CRDTCounter>() {
@Override
public void onChange(CRDTCounter counter) {
if (counter.isValid()) {
counterView.setText(String.format(Locale.US, "%d", counter.getCount()));
} else {
counterView.setText("-");
}
}
});
counterView.setText("0");
}
}
Aggregations