title: Register Account Firebase Through Android App
body: <p><strong>Context:</strong> User opens app -> Clicks on Register -> Fills e-mail &amp; Password -> Account created and returns to main screen.</p>
  
  <p>User can login successful but I have to manually create an account on Firebase Browser in order to do this. I want to do this through the app instead.</p>
  
  <p>Note: I am an amateur in Android-programming.</p>
  
  <p><strong>Activity main</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:baselineAligned="false"&gt;
  
      &lt;ImageView
          android:layout_width="match_parent"
          android:layout_height="163dp"
          app:srcCompat="@drawable/snetech"
          android:id="@+id/imageView" /&gt;
  
      &lt;EditText
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:inputType="textEmailAddress"
          android:ems="10"
          android:id="@+id/emailField"
          android:hint="Email"
          android:paddingTop="20dp" /&gt;
  
      &lt;EditText
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:inputType="textPassword"
          android:ems="10"
          android:id="@+id/passwordField"
          android:hint="Password"
          android:fontFamily="sans-serif"
          android:paddingTop="20dp" /&gt;
  
      &lt;Button
          android:text="Login"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/loginBtn"
          android:paddingTop="20dp" /&gt;
  
      &lt;Button
          android:text="Register"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/registerBtn" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>MainActivity</strong> (Main Screen)</p>
  
  <pre><code>import android.content.Intent;
  import android.os.Bundle;
  import android.support.annotation.NonNull;
  import android.support.v7.app.AppCompatActivity;
  import android.text.TextUtils;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Toast;
  
  import com.google.android.gms.tasks.OnCompleteListener;
  import com.google.android.gms.tasks.Task;
  import com.google.firebase.auth.AuthResult;
  import com.google.firebase.auth.FirebaseAuth;
  
  public class MainActivity extends AppCompatActivity {
  
  private EditText mEmailField;
  private EditText mPasswordField;
  
  private Button mLoginBtn;
  
  private FirebaseAuth mAuth;
  
  private FirebaseAuth.AuthStateListener mAuthListener;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      mAuth = FirebaseAuth.getInstance();
  
      mEmailField = (EditText) findViewById(R.id.emailField);
      mPasswordField = (EditText) findViewById(R.id.passwordField);
  
      mLoginBtn = (Button) findViewById(R.id.loginBtn);
  
      mAuthListener = new FirebaseAuth.AuthStateListener() {
          @Override
          public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
  
              if(firebaseAuth.getCurrentUser() != null) {
  
                  startActivity(new Intent(MainActivity.this, AccountActivity.class));
  
              }
          }
      };
  
      mLoginBtn.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
  
              startSignIn();
  
          }
      });
  }
  
  @Override
  protected void onStart() {
      super.onStart();
  
      mAuth.addAuthStateListener(mAuthListener);
  }
  
  private void startSignIn() {
  
      String email = mEmailField.getText().toString();
      String password = mPasswordField.getText().toString();
  
      if(TextUtils.isEmpty(email) || TextUtils.isEmpty(password)) {
  
          Toast.makeText(MainActivity.this, "Fields are empty!", Toast.LENGTH_LONG).show();
  
      } else {
          mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener&lt;AuthResult&gt;() {
              @Override
              public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
  
                  if(!task.isSuccessful()){
  
                      Toast.makeText(MainActivity.this, "Sign In Problem!", Toast.LENGTH_LONG).show();
                  }
              }
          });
      }
  
  
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>FireApp</strong></p>
  
  <pre><code>import android.app.Application;
  
  import com.firebase.client.Firebase;
  
  /**
   * Created by Mertino11 on 10-Dec-16.
   */
  
  public class FireApp extends Application {
  
  @Override
  public void  onCreate() {
      super.onCreate();
  
      Firebase.setAndroidContext(this);
      }
  }
  </code></pre>
  
  <p><strong>Register XML</strong> (Page where user creates account)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  android:baselineAligned="false"
  android:weightSum="1"&gt;
  
  &lt;ImageView
      android:layout_width="match_parent"
      android:layout_height="163dp"
      app:srcCompat="@drawable/snetech"
      android:id="@+id/imageView" /&gt;
  
  &lt;TextView
      android:text="Register"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:id="@+id/textRegister"
      android:textAlignment="center"
      android:textStyle="normal|bold"
      android:typeface="normal"
      android:textAppearance="@style/TextAppearance.AppCompat"
      android:textSize="36sp"
      android:layout_weight="0.08" /&gt;
  
  &lt;Space
      android:layout_width="match_parent"
      android:layout_height="64dp" /&gt;
  
  &lt;EditText
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:inputType="textEmailAddress"
      android:ems="10"
      android:id="@+id/emailAccount"
      android:hint="Email"
      android:paddingTop="20dp" /&gt;
  
  &lt;EditText
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:inputType="textPassword"
      android:ems="10"
      android:id="@+id/passwordAccount"
      android:hint="Password"
      android:fontFamily="sans-serif"
      android:paddingTop="20dp" /&gt;
  
  &lt;Button
      android:text="Create Account"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:id="@+id/registerAccount" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>How it looks now:</p>
  
  <p><a href="https://i.stack.imgur.com/5zMVm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5zMVm.png" alt="Main Screen"></a></p>
  
  <p><a href="https://i.stack.imgur.com/Qdqf4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qdqf4.png" alt="Registration Page"></a></p>
  
  <p>I know I have to use onClicklistener en some tools of Firebase, but I do not know to code them in a logical way.</p>