Created
September 11, 2016 12:50
-
-
Save ccjeng/deeab608ee7dc644830694071d92ba4f to your computer and use it in GitHub Desktop.
Realm Transaction Block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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