I want to store previous data and the new data in the same child using realtime database in android studio but it store only the new data and deleting the previous data
CodePudding user response:
In case you mean you don't want to overwrite data:
databaseRef.child("categories").push().setValue(category)
using push() will always generate new key and then adds the your data to "categories"
while:
databaseRef.child("categories").setValue(category)
will always overwrite it ..
Hope this helps .. more about how to write to realtime-database here
CodePudding user response:
You cannot store new and previous data in a single child in firebase, as it overwrites the previous data. Still you can create a child under its parent and update them.