Tony Baby Tony Baby - 7 months ago 43
Android Question

How to add data to firebase database from android application

I have an android application that uses firebase for storing data. I want to add new data to the database without overwriting the exiting value.

My code

Firebase ref = new Firebase(Constants.FIREBASE_APP + "/id");

I know this will overwrite the current value. I want to know how to use push() method. Please help


Check the doc:

Using setValue() in this way overwrites data at the specified location, including any child nodes.

You should use the push() method to generate a unique ID every time a new child is added to the specified Firebase reference.

Code (from the comments):

Person person = new Person(); //Adding values person.setName(name); 
Firebase newRef = ref.child("Person").push();