我在实时数据库中有2个表(表User和表Product)。首先,我将数据添加到产品表,然后更新了用户表的数据。更新用户表后,当前活动将重新启动(重新启动)
DatabaseReference databaseReference;
FirebaseDatabase products;
DatabaseReference users;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
firebaseDatabase = FirebaseDatabase.getInstance();
products = firebaseDatabase.getReference("Product");
users = firebaseDatabase.getReference("Users");
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Product product new Product("Android");
products.push().setValue(product)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
users.child("123").child("summa").setValue("newValue");
}
});
}
});
}
所有数据均已正确保存。