gpt4 book ai didi

android - Firebase createUserWithEmailAndPassword 成功,但 oncomplete 从未运行

转载 作者:行者123 更新时间:2023-11-30 00:45:03 26 4
gpt4 key购买 nike

尝试使用 firebase 注册新帐户时,帐户已成功创建,但 OnCompleteListener 从未触发,甚至 OnFailureListener 也未触发。

我正在尝试这样做,以便当尝试登录一个帐户时,系统将首先检查该帐户是否存在,如果它确实尝试登录,如果它没有创建一个新帐户.当我只使用 createUserWithEmailAndPassword 时,创建了一个新帐户,但我的应用程序立即关闭,并且“OnCompleteListener”或“OnFailureListener”下的代码永远不会运行。

我会在logcat中看到这些代码之前和之后的log,但是logcat中没有记录到这些代码里面的log。

auth.signInWithEmailAndPassword(mEmail, mPassword)

.addOnCompleteListener(LoginActivity.this, new OnCompleteListener<AuthResult>()

{

@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.w(TAG, "signInWithEmail:onComplete:" + task.isSuccessful());

// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
auth.createUserWithEmailAndPassword(mEmail, mPassword)
.addOnCompleteListener(LoginActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "Start Testing"+task.getException() );

// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Log.d(TAG, "Testing Not Success" + task.getException());
task.getException();

Log.d(TAG, "Testing Not Success 2" + task.isSuccessful());

}else{
Log.d(TAG, "Testing is Success" + task.isSuccessful());
// startActivity(new Intent(LoginActivity.this, MainMenuActivity.class));
// finish();
}

// ...
}
});
}else{
Log.w(TAG, "signInCompleted");
Toast.makeText(LoginActivity.this, "HI bitch",
Toast.LENGTH_SHORT).show();
LoginActivity.this.startActivity(new Intent(LoginActivity.this, MainMenuActivity.class));
//finish();
}

// ...
}
})
.addOnFailureListener(LoginActivity.this, new OnFailureListener() {

@Override
public void onFailure(@NonNull Exception e) {
Log.d(TAG, "Start Testing"+e );


}
});

最佳答案

我刚刚解决了这个问题,使用 onSuccessListener 而不是 onCompleteListener。我假设此时你要么放弃要么解决了这个问题,但我在任何地方都找不到答案,所以代码应该是这样的

auth.signInWithEmailAndPassword(mEmail, mPassword)
.addOnSuccessListener(LoginActivity.this, new OnSuccessListener<AuthResult>(){

@Override
public void onsuccess(@NonNull AuthResult authResult){
//your code goes here
}
});

关于android - Firebase createUserWithEmailAndPassword 成功,但 oncomplete 从未运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41951897/

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