gpt4 book ai didi

java - onComplete 方法不起作用

转载 作者:行者123 更新时间:2023-12-02 11:13:28 26 4
gpt4 key购买 nike


我正在尝试为 Android 制作一个应用程序。
该应用程序必须有一个登录和注册表单,我不明白为什么方法 onComplete 不起作用,但数据被添加到注册页面的数据库中。
这是代码:

private void submitForm(String email, String password){
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(RegisterActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
FirebaseAuthException e = (FirebaseAuthException)task.getException();
if(task.isSuccessful()){
Toast.makeText(RegisterActivity.this, "Registration successfully!", Toast.LENGTH_SHORT).show();
startActivity(new Intent(RegisterActivity.this, LoginActivity.class));
finish();
}else{
Toast.makeText(RegisterActivity.this, "" +e.getMessage(),
Toast.LENGTH_SHORT).show();
}
}
});
}

private void validate(String email, String password, String confirmPassword){
if(!TextUtils.isEmpty(email)) {
if (android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
if ((!TextUtils.isEmpty(password)) && (!TextUtils.isEmpty(confirmPassword))) {
if (!password.equals(confirmpassword)) {
if(password.length() > 6){
submitForm(email, password);
}else{
Toast.makeText(this, "Password must be at least 6 characters.", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, "Passwords do not match.", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, "Please fill in both password fields.", Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(this, "Please enter a valid email address.", Toast.LENGTH_SHORT).show();
}
}else {
Toast.makeText(this, "Please fill the email field.", Toast.LENGTH_SHORT).show();
}
}

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

auth = FirebaseAuth.getInstance();
email = findViewById(R.id.emailEditText);
password = findViewById(R.id.passwordEditText);
confirmpassword = findViewById(R.id.confirmpasswordEditText);
register = findViewById(R.id.registerbutton);

register.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
validate(email.getText().toString(), password.getText().toString(), confirmpassword.getText().toString());
}
});
}

当我将数据添加到数据库时,我希望在登录页面上被删除。

最佳答案

将 Firebase 更新到最新版本时,请确保同时更新您的 Google Play 服务

在我使用 Firebase 15+ 的情况下,我必须设置 google play 服务(在项目 gradle 中)

classpath 'com.google.gms:google-services:3.3.1'

另请尝试清除数据重新安装应用选项。

关于java - onComplete 方法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50443932/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com