0

I am new to android so there is some problem when i run the code to register or login with firebase authentication i can run the code but when i execute the signup function after pressing the register button it takes a lot time to register 1 account. `

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {

    private FirebaseAuth mAuth;

    private Button btn_register;
    private EditText et_name, et_age, et_email, et_password;
    private ProgressBar ProgressBar;
    private TextView name_project;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        mAuth = FirebaseAuth.getInstance();

        name_project = (TextView) findViewById(R.id.name_project);
        name_project.setOnClickListener(this);

        btn_register = (Button) findViewById(R.id.btn_register);
        btn_register.setOnClickListener(this);

        et_name = (EditText) findViewById(R.id.et_name);
        et_age = (EditText) findViewById(R.id.et_age);
        et_email = (EditText) findViewById(R.id.et_email);
        et_password = (EditText) findViewById(R.id.et_password);
        ProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.name_project:
                startActivity(new Intent(this, MainActivity.class));
                break;
            case R.id.btn_register:
                registerUser();
                break;
        }
    }

    private void registerUser() {
        String email = et_email.getText().toString().trim();
        String password = et_password.getText().toString().trim();
        String name = et_name.getText().toString().trim();
        String age = et_age.getText().toString().trim();

        if (name.isEmpty()) {
            et_name.setError("Please enter your full name");
            et_name.requestFocus();
            return;
        }

        if (age.isEmpty()) {
            et_age.setError("Please enter your age");
            et_age.requestFocus();
            return;
        }

        if (email.isEmpty()) {
            et_email.setError("Please enter your email");
            et_email.requestFocus();
            return;
        }

        if (password.isEmpty()) {
            et_password.setError("Please enter your password");
            et_password.requestFocus();
            return;
        }

        if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
            et_email.setError("Please enter valid email");
            et_email.requestFocus();
            return;
        }

        if (password.length() < 6) {
            et_password.setError("The length of password should be more than 6 letters");
            et_password.requestFocus();
            return;
        }

        ProgressBar.setVisibility(View.VISIBLE);

        mAuth.createUserWithEmailAndPassword(email, password)
                .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                if (task.isSuccessful()) {
                    Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
                    startActivity(intent);
                    finish();
                    Toast.makeText(RegisterActivity.this, "Registered successfully", Toast.LENGTH_SHORT).show();
                    ProgressBar.setVisibility(View.GONE);
                } else {
                    Toast.makeText(RegisterActivity.this, "Registered fail", Toast.LENGTH_SHORT).show();
                    ProgressBar.setVisibility(View.GONE);
                }
            }
        });
    }
}

enter image description here`

I have tried many methods but registration takes a long time.

  • When an app crashes, it writes an error message and stack trace to its logcat. Please find those, and add them to your question by clicking the `edit` link under it. Also see https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this and https://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors – Frank van Puffelen Nov 18 '22 at 03:55
  • Please edit your question and add the information Frank asked for, and please also respond using @. – Alex Mamo Nov 18 '22 at 09:51

1 Answers1

0

Please make sure you have enabled the Email/Password provider in the Authentification tab on the Firebase console.

enter image description here

Aditya Nandardhane
  • 915
  • 1
  • 8
  • 22