title: Firebase Realtime Database & Auth
body: <p>I have recently adopted Firebase for my Backend work. Using Firebase I want to store all the user data like username, phone number, etc to Firebase in the same <code>RegisterActivity</code> and not just Email &amp; Password. How can I achieve this ?</p>
  
  <p>My <code>RegisterActivity</code> will only appear at the time of installation. When user have register to my app, I am destroying the activity. So, there is no instance of <code>RegisterActivity</code> further. </p>
  
  <p><code>RegisterActivity - onCreate()</code>:</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      Firebase.setAndroidContext(this);
      setContentView(R.layout.activity_register);
  
      initialization();
      underlineText();    //Underlining Text in App
  
      userObj = new User();
      userObj.setName(NAME);
      userObj.setEMAIL(EMAIL);
      userObj.setPHONE(PHN);
  
      animShake = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.shake);     //Animation
  
      vib = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);    //Vibration
  
      reg.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              submitForm();   //Registration Click Listener
          }
      });
  
      skip.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              skipRegistrationSection();  //Skip Click Listener
          }
      });
  
      runAtInstallation();
  }
  </code></pre>
  
  <p><code>submitform()</code>:</p>
  
  <pre><code>private void submitForm() {
  
      if (!checkName()) {
          name.setAnimation(animShake);
          name.startAnimation(animShake);
          vib.vibrate(60);
          return;
      }
      if (!checkEmail()) {
          email.setAnimation(animShake);
          email.startAnimation(animShake);
          vib.vibrate(60);
          return;
      }
      if (!checkPhone()) {
          phone.setAnimation(animShake);
          phone.startAnimation(animShake);
          vib.vibrate(60);
          return;
      }
      if (!checkPassword()) {
          password.setAnimation(animShake);
          password.startAnimation(animShake);
          vib.vibrate(60);
          return;
      }
      if (!checkConfirmPassword()) {
          confirmPassword.setAnimation(animShake);
          confirmPassword.startAnimation(animShake);
          vib.vibrate(60);
          return;
      }
  
      nameLayout.setErrorEnabled(false);
      emailLayout.setErrorEnabled(false);
      phoneLayout.setErrorEnabled(false);
      passwordLayout.setErrorEnabled(false);
      confirmPasswordLayout.setErrorEnabled(false);
  
      NAME = name.getText().toString().trim();
      EMAIL = email.getText().toString().trim();
      PHN = phone.getText().toString().trim();
      PASSWORD = password.getText().toString();
  
      progressBar.setVisibility(View.VISIBLE);
  
      authUser();     //authenticating  User via Email &amp; Password
  
  }
  </code></pre>
  
  <p><code>authUser()</code>:</p>
  
  <pre><code>private void authUser() {
  
      mFirebaseAuth.createUserWithEmailAndPassword(EMAIL, PASSWORD).addOnCompleteListener(RegisterActivity.this, new OnCompleteListener&lt;AuthResult&gt;() {
          @Override
          public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
  
              if (!task.isSuccessful()) {
                  AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
                  builder.setMessage(task.getException().getMessage())
                          .setTitle("Error")
                          .setPositiveButton(android.R.string.ok, null);
                  AlertDialog dialog = builder.create();
                  dialog.show();
                  progressBar.setVisibility(View.GONE);
              } else {
                  progressBar.setVisibility(View.GONE);
  
                  Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
                  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                  startActivity(intent);
              }
          }
  
      });
  }
  </code></pre>
  
  <p><code>runAtInstallation</code>:</p>
  
  <pre><code>private void runAtInstallation() {
  
      SharedPreferences pref = getSharedPreferences("ActivityPREF", Context.MODE_PRIVATE);
      if (pref.getBoolean("activity_executed", false)) {
  
          Intent act = new Intent(getApplicationContext(), MainActivity.class);
          act.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          act.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
          startActivity(act);
          finish();
      } else {
          SharedPreferences.Editor ed = pref.edit();
          ed.putBoolean("activity_executed", true);
          ed.commit();
      }
  }
  </code></pre>
  
  <p>I want to save name,email,&amp; phone in the firebase database during registration and to destroy the activity after that.</p>