title: implementing Android login features for new Firebase
body: <p>I'm trying to update my android code in the new Firebase after May 2016's update, but am running into issues. Previously my user create worked fine with </p>
  
  <pre><code>        Firebase ref = new Firebase("https://project.firebaseio.com");
          ref.createUser(email, password, new Firebase.ValueResultHandler&lt;Map&lt;String, Object&gt;&gt;() {
              @Override
              public void onSuccess(Map&lt;String, Object&gt; result) {
                  System.out.println("Successfully created user account with uid: " + result.get("uid"));
                  error.setText("Account successfully created.");
              }
              @Override
              public void onError(FirebaseError firebaseError) {
                  error.setText("Error with account creation");
              }
          });
  </code></pre>
  
  <p>but with the new system where I'm told I need to implement the system here: <a href="https://firebase.google.com/docs/auth/android/password-auth" rel="nofollow">https://firebase.google.com/docs/auth/android/password-auth</a>, I'm getting error </p>
  
  <pre><code>Cannot resolve method AddOnCompleteListener
  </code></pre>
  
  <p>whenever I try to put the method inside of an Android clickListener (how I'm sending the login data)</p>
  
  <p>My (relevant) code is </p>
  
  <pre><code>    FirebaseAuth mAuth = FirebaseAuth.getInstance();
      FirebaseAuth.AuthStateListener mAuthListener;
  
  
  protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.content_login);
  
  
              mAuthListener = new FirebaseAuth.AuthStateListener() {
                  @Override
                  public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                      FirebaseUser user = firebaseAuth.getCurrentUser();
                      if (user != null) {
                          // User is signed in
                          //Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
                      } else {
                          // User is signed out
                         // Log.d(TAG, "onAuthStateChanged:signed_out");
                      }
                      // ...
                  }
              };
  
      @Override
      protected void onStart() {
          super.onStart();
  
      mAuth.addAuthStateListener(mAuthListener);
  
          mCreateNew.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
     EditText editText = (EditText) findViewById(R.id.email);
                  String email = editText.getText().toString();
                  editText = (EditText) findViewById(R.id.password);
                  String password = editText.getText().toString();
  
  
  
               mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener&lt;AuthResult&gt;() {
                  @Override
                  public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                      Log.d(logStr, "createUserWithEmail:onComplete:" + task.isSuccessful());
  
                      // If sign in fails, display a message to the user. If sign in succeeds
                      // the auth state listener will be notified and logic to handle the
                      // signed in user can be handled in the listener.
                      if (!task.isSuccessful()) {
                          Toast.makeText(getApplicationContext(), "Authentication failed.",
                                  Toast.LENGTH_SHORT).show();
                      }
  
                  }
              });
          }
      });
  }
  
  
  mLogin.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  EditText editText = (EditText) findViewById(R.id.email);
                  String email = editText.getText().toString();
                  editText = (EditText) findViewById(R.id.password);
                  String password = editText.getText().toString();
  
  mAuth.signInWithEmailAndPassword(email, password)
                          .addOnCompleteListener(this, new OnCompleteListener&lt;AuthResult&gt;() {
                              @Override
                              public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                                  Log.d(logStr, "signInWithEmail:onComplete:" + task.isSuccessful());
  
                                  // If sign in fails, display a message to the user. If sign in succeeds
                                  // the auth state listener will be notified and logic to handle the
                                  // signed in user can be handled in the listener.
                                  if (!task.isSuccessful()) {
                                      Log.w(logStr, "signInWithEmail", task.getException());
                                      Toast.makeText(getApplicationContext(), "Authentication failed.",
                                              Toast.LENGTH_SHORT).show();
                                  }
  
                              }
                          });
  
  
  
              }
          });
  </code></pre>
  
  <p>Reading through the new Firebase guide, it mentions that these new listeners wait for an update on the user's "sign in state" but doesn't really go into detail on that. How do I make it so that I can call the sign-in/create-new only when I click the buttons?</p>
  
  <p>I know that taking the code outside of the clicklistener "solves" the problem, but then I don't know how to be able to control when the user sends login data.</p>