Firebase中保存数据的方式是用户ID位于每个推送ID下,而它应该是另一种方式;这是用户ID下的推送ID。
我的代码需要更改什么?
private void saveServiceDetails(){
adService1 adService1 = new adService1(Name, Description, Category, downloadUrl, lat, lng);
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Saving information..., please wait");
progressDialog.show();
FirebaseUser user = firebaseAuth.getCurrentUser();
databaseReference.child(user.getUid()).setValue(adService1)
.addOnCompleteListener(this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()){
progressDialog.dismiss();
Toast.makeText(getApplicationContext(), "Information saved...", Toast.LENGTH_LONG).show();
}
}
});
}
答案 0 :(得分:0)
试试这段代码:
....
FirebaseUser user = firebaseAuth.getCurrentUser();
String key = databaseReference.child(user.getUid()).push().getKey();
databaseReference.child(user.getUid()).child(key).setValue(adService1)
.addOnCompleteListener(this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()){
progressDialog.dismiss();
Toast.makeText(getApplicationContext(), "Information saved...", Toast.LENGTH_LONG).show();
}
}
});