title: Read and write values in Firebase Database problem
body: <p>I want to read 2 values from Firebase (if exist as in first user there are not) and if needed to update them. Actually i m trying at first to do it with one value, with no luck. My code is</p>
  
  <pre><code>mAuthListener = new FirebaseAuth.AuthStateListener() {
          @Override
          public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
              FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
              if (user != null) {
                  final String uid = Objects.requireNonNull( mAuth.getCurrentUser() ).getUid();
                  mScoreReference.child( uid ).addListenerForSingleValueEvent( new ValueEventListener() {
                      @Override
                      public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                          User oldscore = dataSnapshot.getValue( User.class );
                          if (dataSnapshot.exists()) {
                              if(oldscore.getScore()==null){
                                  oldscore.setScore(String.valueOf( 0));
                                  String oldscorevalue = Objects.requireNonNull(oldscore).getScore();
                                  int convertedscore = Integer.parseInt(oldscorevalue);
                                  if (convertedscore &gt; 0) {
                                      //Upload points to Database
                                      mScoreReference.child(uid).child( "Score" )
                                              .setValue( convertedscore + newScore );
  
                                  } else mScoreReference.child(uid).child( "Score" ).setValue( newScore );
  
                              }
  
                          }
  
  
                      }
  
                      @Override
                      public void onCancelled(@NonNull DatabaseError databaseError) {
  
                      }
  
  
                  } );
  </code></pre>
  
  <p>I managed to convert null(the first value as score is not exist) and to set score. So my problem is why i cant update the value, and how can i update 2 values at the same time? Probably i have to use Transaction, but i m not familiar at all with this. I m reading, but i cant find how to convert this code to Transaction.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I tried with Transaction. </p>
  
  <pre><code>mScoreReference.child( uid ).runTransaction(new Transaction.Handler() {
                      @Override
                      public Transaction.Result doTransaction(MutableData mutableData) {
                          User user = mutableData.getValue(User.class);
                          if (user.getScore() == null) {
                              mScoreReference.child(uid).child( "Score" ).setValue( newScore );
                          }
                          else{
                              String oldscorevalue = Objects.requireNonNull(user).getScore();
                              int convertedscore = Integer.parseInt(oldscorevalue);
                              mScoreReference.child(uid).child( "Score" )
                                      .setValue( convertedscore + newScore );
                          }
  
                          // Set value and report transaction success
                          mutableData.setValue(user);
                          return Transaction.success(mutableData);
                      }
  
                      @Override
                      public void onComplete(DatabaseError databaseError, boolean b,
                                             DataSnapshot dataSnapshot) {
                          // Transaction completed
                          Log.d(TAG, "postTransaction:onComplete:" + databaseError);
                      }
                  });
  </code></pre>
  
  <p>and i have strange results. At first time do nothing, then adds Score and another irelavent User value, and after this adds 2 Score fields in Database.</p>