Skip to content

Instantly share code, notes, and snippets.

@ccjeng
Created September 11, 2016 12:50
Show Gist options
  • Save ccjeng/deeab608ee7dc644830694071d92ba4f to your computer and use it in GitHub Desktop.
Save ccjeng/deeab608ee7dc644830694071d92ba4f to your computer and use it in GitHub Desktop.
Realm Transaction Block
public void addPerson() {
final Realm realm = Realm.getDefaultInstance();
//It automatically handles begin/commit, and cancel if an error happens
realm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
Person p = realm.createObject(City.class);
p.setId("00002");
c.setName("Steve Jobs");
}
}, new Realm.Transaction.OnSuccess() {
@Override
public void onSuccess() {
realm.close();
}
}, new Realm.Transaction.OnError() {
@Override
public void onError(Throwable error) {
Log.e(TAG, error.getMessage());
realm.close();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment