title: How to check if writing task was successful in Firebase
body: <p>I'm totally new to Firebase and need to know how to check if my writing task was successful because if I don't, the <code>MainActivity</code> starts and messes up my <code>Register</code> progress.</p>
  
  <p>This checks if <code>Username</code> is already taken and registers the user if it isn't:</p>
  
  <pre><code>Query usernamequery = myRef.orderByChild("Username").equalTo(Username);
  
  usernamequery.addListenerForSingleValueEvent(new ValueEventListener() {
      @Override
      public void onDataChange(DataSnapshot snapshot) {
          if (snapshot.exists()) {
              // TODO: handle the case where the data already exists
              editText.setError("Username taken!");
              return;
          }
          else {
              // TODO: handle the case where the data does not yet exist
              myRef.child("Users").child(Username).child("Userid").setValue(user.getUid());
              myRef.child("Users").child(Username).child("Username").setValue(Username);
              startActivity(maps);
              finish();
          }
      }
  
      @Override
      public void onCancelled(DatabaseError databaseError) {
          Toast.makeText(Username.this, "Error", Toast.LENGTH_LONG).show();
      }
  });
  </code></pre>
  
  <p>But I want the Intent to Main Activity (maps) only be fired when 
  <code>myRef.child("Users").child(Username).child("Userid").setValue(user.getUid());</code></p>
  
  <p>and the other one is finished with its task and is successful.</p>
  
  <p>What can I do?</p>