[英]I am using following code to save data on firebase .but data dont save in firebase , how can I fix it?
creat_acount_button=(Button)findViewById(R.id.creat_acountID); creat_acount_button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final String name=username.getText().toString().trim(); String em=email.getText().toString().trim(); String pass=password.getText().toString().trim(); final String phoneNum=phone.getText().toString().trim(); final String loc=location.getText().toString().trim(); final String desc=description.getText().toString().trim(); if (!TextUtils.isEmpty(name)&&!TextUtils.isEmpty(loc)&&!TextUtils.isEmpty(em)&&!TextUtils.isEmpty(pass)&&!TextUtils.isEmpty(desc)) { mProgress.setMessage("Creating Acount"); mProgress.show(); mAuth.createUserWithEmailAndPassword(em,pass) .addOnSuccessListener(new OnSuccessListener<AuthResult>() { @Override public void onSuccess(AuthResult authResult) { if (authResult!=null) { String userid=mAuth.getCurrentUser().getUid(); DatabaseReference curentuserDB=mDatabaseReference.child(userid); curentuserDB.child("UserName").setValue(username); curentuserDB.child("phone").setValue(phoneNum); curentuserDB.child("location").setValue(loc); curentuserDB.child("Description").setValue(desc); mProgress.dismiss(); Intent intent = new Intent(Register.this,Post.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } } }); } } });
嘗試像這樣添加故障偵聽器,並輸出錯誤(如果存在):
mAuth.createUserWithEmailAndPassword(em,pass).addOnCompleteListener(task -> {
//Successful
if(task.isSuccessful()){
String userid=mAuth.getCurrentUser().getUid();
DatabaseReference curentuserDB=mDatabaseReference.child(userid);
curentuserDB.child("UserName").setValue(username);
curentuserDB.child("phone").setValue(phoneNum);
curentuserDB.child("location").setValue(loc);
curentuserDB.child("Description").setValue(desc);
mProgress.dismiss();
Intent intent = new Intent(Register.this,Post.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
//Error
else {
Log.d("Error", Objects.requireNonNull(Objects.requireNonNull(task.getException()).getLocalizedMessage()));
}
}).addOnFailureListener(e -> {
Log.d("Error", Objects.requireNonNull(e.getLocalizedMessage()));
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.