[This is my json dataThis is my code ][1]
I am trying to change the value of the key-value pair in the Firebase database. Lets suppose I have a key value like this:"chemistry":"20".I want to extract the value of the key chemistry and want to update it after adding some number like I add 10 to it so my final key value pair will become "chemistry":"30" .But I am unable to access the key can someone help me with this.
My code goes here:
mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d("TAG", "signInWithEmail:success");
//extracting the current user from the databse
FirebaseUser user = mAuth.getCurrentUser();
//getting the uid of the user
String Uid=user.getUid();
//getting the databse instance for the particular user
FirebaseDatabase database = FirebaseDatabase.getInstance();
//setting the path to the Users/Uid to read the key values
DatabaseReference myRef = database.getReference("Users/"+Uid);
//textView.setText(myRef);
String key=myRef.child("chemistry").getKey();
textView.setText(key);
// myRef.setValue("Hello, World!");
} else {
// If sign in fails, display a message to the user.
Log.w("TAG", "signInWithEmail:failure", task.getException());
Toast.makeText(TestActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
//updateUI(null);
}
// ...
}
});
my json is here:
{
"Users" : {
"LMn5GeZixNQNpdQhGzdKNbTgIw53" : {
"chemistry" : "20",
"email" : "umairnsr87@gmail.com",
"lastScore" : "0",
"maths" : "0",
"name" : "umair",
"phone" : "123456789",
"physics" : "0"
}
}
}