我使用下面的代码将postingdata
添加到firebase中。问题是,当我在finish
中评论onComplete
方法时,我的所有数据都在firebase数据库中正确写入。但是当我取消注释finish
方法时,大多数数据都不会写入数据库。我想用finish
方法写完整数据。
mUserRefrence.child(user.getUid()).setValue(postingdata).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
hideProgressDialog();
Toast.makeText(LoginActivity.this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
}
}).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
hideProgressDialog();
Toast.makeText(LoginActivity.this, getString(R.string.login_success), Toast.LENGTH_SHORT).show();
startActivity(new Intent(LoginActivity.this, MainActivity.class));
finish();
}
});
答案 0 :(得分:0)
}).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (!task.issuccessful()) {
// this piece of code will execute if task is Unsuccessful
hideProgressDialog();
Toast.makeText(LoginActivity.this, getString(R.string.login_Unsuccess), Toast.LENGTH_SHORT).show();
}
else {
// this piece of cade will execute if task is successful
hideProgressDialog();
startActivity(new Intent(LoginActivity.this, MainActivity.class));
finish();
}
}
});
答案 1 :(得分:0)
Firebase数据库规则模拟器存在问题。请查看状态链接:https://status.firebase.google.com/incident/Console/17012,现在显示已解决。