android – Firebase add new child with specified name

android – Firebase add new child with specified name

It happens because you are using:

Firebase usersRef = ref.child(Users);
usersRef.setValue(name);

In this way you will push the value in url/Users removing the previous value.

Check the doc:

Using setValue() will overwrite the data at the specified location, including any child nodes.

To add a new user without removing the previous one , just remove this line:

//usersRef.setValue(name);

In this way you will push the value in url/Users/myName without overriding other values.

Firebase Database Push

[FirebaseDatabase mydb =][2] FirebaseDatabase.getInstance();
DatabaseReference mDatabase = mydb.getReference().child(Dealers).child(dealerId).child(Stock).child(stockAddDate);

Map<String, String> userData = new HashMap<String, String>();

userData.put(Product_Name, productName);
userData.put(Holding_Stock, holdingStock);
userData.put(Primary_Stock, primaryStock);
mDatabase.push().setValue(userData);

Just use PUSH before setValue.

android – Firebase add new child with specified name

This worked for me. I am using model class instead of Hash

mFirebaseDatabase.child(name);
mFirebaseDatabase = mFirebaseDatabase.child(name);
FirebaseDatabase.setValue(name);
FirebaseDatabase.setValue(user);

Leave a Reply

Your email address will not be published.