I have a button for logged in users. When a logged in user clicks the button, I want to increase a specific value for this specific user. Now I am using the below code, but it creates a child in a Firebase database and increases data. I want that it should increase a specific (logged in) user child ("points") data.
myRef.child("points").runTransaction(new Transaction.Handler() {
@Override
public Transaction.Result doTransaction(final MutableData currentData) {
if (currentData.getValue() == null) {
currentData.setValue("0");
} else {
String stringValue = (String) currentData.getValue();
int intValue = Integer.parseInt(stringValue);
int increasedIntValue = intValue + 1;
currentData.setValue(String.valueOf(increasedIntValue));
}
return Transaction.success(currentData);
}
@Override
public void onComplete(DatabaseError databaseError, boolean committed, DataSnapshot currentData) {
if (databaseError != null) {
System.out.println("Firebase counter increment failed!");
} else {
System.out.println("Firebase counter increment succeeded!");
}
}
});
The database:
What can I do now?