title: Method returning value before code can run to update the value
body: <p>In the below example, I call a method <code>signinUser(username, password)</code> This then runs through Firebase to determine if the user has successfully or unsuccessfully been able to sign in. However, it takes Firebase a short amount of time to do this, which by that time the method has already returned with the original value, before being updated by the successful-ness / unsuccessful-ness of the sign in process.</p>
  
  <p>How would I go about returning the method once the Firebase authentication has done it's thing. I am aware I could put a timer on when the return statement is called, however, I'm not sure how that'd work as slow internet connects could cause it to take longer than the given amount set by a timer.</p>
  
  <p>My code is as follows:</p>
  
  <pre><code>public AuthSuccess signinUser(String username, String password) {
          mAuth.signInWithEmailAndPassword(username + "@debugrestaurant.com", password)
                  .addOnCompleteListener(new OnCompleteListener&lt;AuthResult&gt;() {
                      @Override
                      public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                          if (task.isSuccessful()) {
                              Toast.makeText(context, "Successful!", Toast.LENGTH_SHORT).show();
                              authSuccess = new AuthSuccess(true, null);
                          } else {
                              Toast.makeText(context, "Unsuccessful!", Toast.LENGTH_SHORT).show();
                              authSuccess = new AuthSuccess(false, task.getException());
                              Toast.makeText(context, "Exception: " + authSuccess.getException().getLocalizedMessage(), Toast.LENGTH_SHORT).show();
                          }
                      }
                  });
          return authSuccess;
      }
  </code></pre>
  
  <p>Please note that the class <code>AuthSuccess</code> is simply an object I've created to collect whether or not the sign in was successful, and if not, to collect the exception.</p>