简体   繁体   English

在 firebase 数据库上执行注册 function 时不断崩溃

[英]Constantly crashes when performing registration function on firebase database

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.我是 android 的新手,所以当我运行代码注册或使用 firebase 身份验证登录时出现一些问题,我可以运行代码但是当我在按下注册按钮后执行注册 function 时,注册 1 个帐户需要很多时间。 ` `

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.我尝试了很多方法,但注册需要很长时间。

Please make sure you have enabled the Email/Password provider in the Authentification tab on the Firebase console.请确保您已在 Firebase 控制台的身份验证选项卡中启用电子邮件/密码提供程序。

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 firebase 云 function 对文档执行多项操作时如何正确使用'return' - How to properly use 'return' in a firebase cloud function when performing multiple actions against documents 在 Firebase 实时数据库(在 Android 中)中对 Firebase 身份验证使用自定义注册? - Using custom registration for Firebase authentication in Firebase Realtime Database (in Android)? Firebase Crashlytics 在手动启用时不报告崩溃 - Firebase Crashlytics not reporting crashes when manually enabled 将图像发送到 Firebase 存储时应用程序崩溃 - App crashes when sending image to Firebase storage 尝试从 Firebase 中读取 Firebase 数据库时无法确定 Firebase 数据库 URL Node.js Firebase function - Can't determine Firebase Database URL when trying to read Firebase Database from within Node.js Firebase function Firebase 模拟器在退出时崩溃(通常) - Firebase Emulator crashes when exporting on exit (usually) Firebase SDK 缺少数据库() function - Firebase SDK is missing database() function Function.database 和 Firebase.database 有什么区别? 什么时候使用一个而不是另一个? - What is the difference between Function.database and Firebase.database? When to use one over the other? iOS 应用程序在尝试使用 Firebase 身份验证“使用 Apple 登录”时崩溃 - iOS app crashes when trying to "Sign in with Apple" using Firebase Authentication Firebase 云功能不更新 Firestore 数据库中的数据 - Firebase Cloud function not updating data in Firestore database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM