我有以下代码,我想检查交易的成功/失败以生成特定的Toast消息。谢谢!
buttonOK.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
realm.beginTransaction();
transactions obj = realm.createObject(transactions.class);
obj.setOperatrice(txtoperatrice.getText().toString());
obj.setOperation(txtoperation.getText().toString());
realm.commitTransaction();
}
});
答案 0 :(得分:1)
您可以像这样使用回调-
realm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm bgRealm) {
User user = bgRealm.createObject(User.class);
user.setName("John");
user.setEmail("john@corporation.com");
}
}, new Realm.Transaction.OnSuccess() {
@Override
public void onSuccess() {
// Transaction was a success.
}
}, new Realm.Transaction.OnError() {
@Override
public void onError(Throwable error) {
// Transaction failed and was automatically canceled.
}
});
希望它会对您有所帮助。