i tried to update the number of points of specific user and i dont know why it is dont work.
dbReference.child(uname).child(“points”).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (snapshot.exists()) {
int points2 = snapshot.getValue(Integer.class) + pointsToAdd;
Log.i(“TAG2″, points2+””);
Map<String, Object> update = new HashMap<>();
update.put("points", points2);
dbReference.child(uname).updateChildren(update)
.addOnSuccessListener(aVoid -> Log.i("TAG2", "Hello"))
.addOnFailureListener(e -> Log.i("TAG2", "No"));
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
Log.e("TAG2", "Error fetching points", error.toException());
}
});
{
“rules”: {
“.read”: true,
“.write”: true
}
}
Osher Benaim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.