我需要通过Android中的事务添加新的键值对。有没有办法做到这一点?
答案 0 :(得分:1)
MutableData
中的doTransaction()
对象有一个child()
方法,可用于读取/写入子数据。
ref.runTransaction(new Transaction.Handler() {
@Override
public Transaction.Result doTransaction(MutableData currentData) {
currentData.child("my new child").setValue(1);
return Transaction.success(currentData);
}
@Override
public void onComplete(FirebaseError firebaseError, boolean committed, DataSnapshot currentData) {
//This method will be called once with the results of the transaction.
}
});