我跟随在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();
}
// ...
}
});
}
我预计将有举杯说“任务成功”,因为它有它进入到火力用户数据库
你有没有设定onClickListener
为您的观点应该触发CreateNewUser
方法?您Activity
正在实施的接口。在onCreate
你应该调用是这样的:
findViewById(R.id.myButton).setOnClickListener(this);
凡myButton
是你activitys XML定义的View
的ID。