📌  相关文章
📜  更新firebase实时数据库中的一个键java代码示例

📅  最后修改于: 2022-03-11 14:52:24.194000             🧑  作者: Mango

代码示例1
myRef.orderByChild("name").equalTo("abc").runTransaction(new Transaction.Handler() {
    @Override
    public Transaction.Result doTransaction(MutableData mutableData) {
        Student s = mutableData.getValue(Student.class);
        if (s == null) {
            return Transaction.success(mutableData);
        }

        s.setAge(20);
        // Set value and report transaction success
        mutableData.setValue(s);
        return Transaction.success(mutableData);
    }

    @Override
    public void onComplete(DatabaseError databaseError, boolean b,
                           DataSnapshot dataSnapshot) {
        // Transaction completed
        Log.d(TAG, "postTransaction:onComplete:" + databaseError);
    }
});