title: Android how to wait for onComplete method to end before proceeding to the next code
body: <p>I want to get a boolean from my onComplete function before proceeding to the next step.</p>
  
  <p>My problem is that when code gets to the part when my boolean (isLoginSucces) is crucial to my code, it get's only false value, because onComplete function did not arrived at the point when it changes the value of the boolean.</p>
  
  <p>I tried async function, but it didn't work, tried aswell AtomicBoolean, didn't worked too. </p>
  
  <p>After that, i did put even Thread.sleep(10000). In that time(10 seconds) it surely changed the value, but don't work too, still false, i don't get it.</p>
  
  <pre><code>    private String loginButtonClicked () {
  
              mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(getActivity(), new OnCompleteListener&lt;AuthResult&gt;() {
                  @Override
                  public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                      if (task.isSuccessful()) {
                          ...
                          LoginFragment.this.isLoginSucces = true;
                          Log.d("boolean", "boolean value in onComplete: " + isLoginSucces);
                      } else {
                          ...
                          LoginFragment.this.isLoginSucces = false;
                      }
                  }
              });
  
              //HERE I tried Thread.sleep(10000);
              Log.d("boolean", "boolean value after function: " + isLoginSucces);
  
              if (LoginFragment.this.isLoginSucces)
                  return email;
              else
                  return null;
  
      }
  </code></pre>
  
  <blockquote>
    <p>The log output is :</p>
    
    <p>2019-03-29 18:45:12 D/boolean: boolean value after function: false</p>
    
    <p>2019-03-29 18:45:14 D/boolean: boolean value in onComplete: true</p>
  </blockquote>