如何修复错误,从开始引起addOnCompleteListener()

问题描述 投票:0回答:1

我跟随在Android Studio中的指令火力地堡验证添加到应用程序。该代码添加新用户,但没有表现出它想敬酒。我试图调试代码,看到它TASE没有进入方法“完成”在此处输入代码

public class Register extends AppCompatActivity implements View.OnClickListener,  OnCompleteListener<Void> {


private FirebaseAuth mAuth;
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);

    mAuth = FirebaseAuth.getInstance();

}
@Override
public void onStart() {
    super.onStart();
    // Check if user is signed in (non-null) and update UI accordingly.
    FirebaseUser currentUser = mAuth.getCurrentUser();
   // updateUI(currentUser);
}

@Override
public void onClick(View view) {
    CreateNewUser();
}
private void CreateNewUser()
{
    //creates a new user and adds it to firebase
    //uses the mail and password in the edit text
    final String TAG="tag";
    mAuth.createUserWithEmailAndPassword("example @gmail.com","1234567")
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        // Sign in success, update UI with the signed-in user's information
                        Toast.makeText(Register.this,"Task is successful",Toast.LENGTH_SHORT).show();
                        Log.d(TAG, "createUserWithEmail:success");
                        FirebaseUser user = mAuth.getCurrentUser();


                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w(TAG, "createUserWithEmail:failure", task.getException());
                        Toast.makeText(Register.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();

                    }

                    // ...
                }
            });
}

我预计将有举杯说“任务成功”,因为它有它进入到火力用户数据库

android firebase firebase-authentication
1个回答
0
投票

你有没有设定onClickListener为您的观点应该触发CreateNewUser方法?您Activity正在实施的接口。在onCreate你应该调用是这样的:

findViewById(R.id.myButton).setOnClickListener(this);

myButton是你activitys XML定义的View的ID。

© www.soinside.com 2019 - 2024. All rights reserved.