firebase身份验证-在控制台中创建用户,但进度条不会停止旋转,任务也不会完成?

oewdyzsn  于 2021-08-25  发布在  Java
关注(0)|答案(1)|浏览(266)

因此,我正在为一个移动应用程序编写注册表,当用户填写注册表并提交时,进度条会出现并无限旋转,令人惊讶的是,没有打印任何消息。尽管如此,用户还是出现在firebase控制台上,这让我难以置信。
代码:

progressBar.setVisibility(View.VISIBLE);
            mAuth.createUserWithEmailAndPassword(email, password)
                    .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            if(task.isSuccessful()) {
                                User user = new User(fullName, rating, email);

                                System.out.println(user.fullName);

                                FirebaseDatabase.getInstance().getReference("Users")
                                        .child(FirebaseAuth.getInstance().getCurrentUser().getUid())
                                        .setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() {
                                    @Override
                                    public void onComplete(@NonNull Task<Void> task) {
                                        if(task.isSuccessful()) {
                                            Toast.makeText(RegisterUser.this, "User has been registered succesfully!", Toast.LENGTH_LONG).show();
System.out.println("Success!");
                                            progressBar.setVisibility(View.GONE);
                                        }else {
                                            Toast.makeText(RegisterUser.this, "Failed to register! 
 Try again!", Toast.LENGTH_LONG).show();
System.out.println("Failure!");
                                            progressBar.setVisibility(View.GONE);
                                        }
                                    }
                                });
                            }
                        }
                    });

谢谢

piah890a

piah890a1#

FirebaseDatabase.getInstance().getReference("Users")
                                            .child(FirebaseAuth.getInstance().getCurrentUser().getUid())
                                            .setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() {
                                        @Override
                                        public void onComplete(@NonNull Task<Void> task) {
                                            if(task.isSuccessful()) {
                                                Toast.makeText(RegisterUser.this, "User has been registered succesfully!", Toast.LENGTH_LONG).show();
    System.out.println("Success!");
                                                progressBar.setVisibility(View.GONE);
                                            }else {
                                                Toast.makeText(RegisterUser.this, "Failed to register! 
     Try again!", Toast.LENGTH_LONG).show();
    System.out.println("Failure!");
                                                progressBar.setVisibility(View.GONE);
                                            }
                                        }
                                    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
 progressBar.setVisibility(View.GONE)
        }
    });

添加此失败侦听器。所以你可以得到失败的消息或做你想做的事。

相关问题