title: Firebase Auth not working in Async Task
body: <p>I am using Firebase Auth (registering a new user) , it worked perfectly on the Main Thread but when i moved it to the background , Authentication always failed .
  Here is the the method for creating a new user :</p>
  
  <pre><code> public void createAccount(String email, String password) {
      mAuth.createUserWithEmailAndPassword(email, password)
              .addOnCompleteListener(this, new OnCompleteListener&lt;AuthResult&gt;() {
                  @Override
                  public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                      Log.d(TAG, "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(registerActivity.this, "bad",
                                  Toast.LENGTH_SHORT).show();
                          sr = false;
  
                      } else {
  
                          FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
                          if (user != null) {
  
                              EditText etname = (EditText) findViewById(R.id.etName);
                              EditText etlname = (EditText) findViewById(R.id.etLName);
                              String namez = etname.getText().toString();
                              String lnamez = etlname.getText().toString();
                              DatabaseReference mDatabase;
                              mDatabase = FirebaseDatabase.getInstance().getReference();
                              Toast.makeText(registerActivity.this, "good", Toast.LENGTH_SHORT).show();
                              String UID = user.getUid();
                              mDatabase.child("users").child(UID + "_lname").setValue(lnamez);
                              mDatabase.child("users").child(UID + "_name").setValue(namez);
                              sr = true;
                          }
                      }
  
                      // ...
                  }
              });
  }
  </code></pre>
  
  <p>and here is the AsyncTask :</p>
  
  <pre><code> private class createInBack extends AsyncTask&lt;Void, Void, Void&gt; {
  //Executes the 'createAccount' method in background .
  EditText etemail = (EditText) findViewById(R.id.etEmail);
      EditText etpassword = (EditText) findViewById(R.id.etPassword);
      String email = etemail.getText().toString();
      String password = etpassword.getText().toString();
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
          spinner.setVisibility(View.VISIBLE);
  
      }
      @Override
      protected Void doInBackground(Void... voids) {
  
          createAccount(email, password);
          return null;
      }
      @Override
      protected void onPostExecute(Void aVoid) {
          super.onPostExecute(aVoid);
          if(sr){
              Toast.makeText(registerActivity.this, "we good here", Toast.LENGTH_SHORT).show();
              startActivity(new Intent(registerActivity.this, MainActivity.class));
          }
          spinner.setVisibility(View.GONE);
      }
  }
  </code></pre>
  
  <p>so what is the problem ?</p>