update a key in the firebase realtime database java

Solutions on MaxInterview for update a key in the firebase realtime database java by the best coders in the world

showing results for - "update a key in the firebase realtime database java"
Vincenzo
27 Oct 2020
1myRef.orderByChild("name").equalTo("abc").runTransaction(new Transaction.Handler() {
2    @Override
3    public Transaction.Result doTransaction(MutableData mutableData) {
4        Student s = mutableData.getValue(Student.class);
5        if (s == null) {
6            return Transaction.success(mutableData);
7        }
8
9        s.setAge(20);
10        // Set value and report transaction success
11        mutableData.setValue(s);
12        return Transaction.success(mutableData);
13    }
14
15    @Override
16    public void onComplete(DatabaseError databaseError, boolean b,
17                           DataSnapshot dataSnapshot) {
18        // Transaction completed
19        Log.d(TAG, "postTransaction:onComplete:" + databaseError);
20    }
21});
22
similar questions