Satveer Bhantoo
Satveer Bhantoo

Reputation: 81

Getting key of inserted object in firebase android

How do i retrieve the key of a newly inserted object in firebase.. The Object was inserted using android using setValue()

firebaseDatabaseRef.push().setValue(user); 

Where user is a java object..

I need to key to update an attribute in my object.

The firebase ref is already pointing at the node in which the children are added.

Upvotes: 0

Views: 1800

Answers (1)

Th0rndike
Th0rndike

Reputation: 3436

To get the key:

String Key = firebaseDatabaseRef.push().getKey();

then you can set value:

firebaseDatabaseRef.child(Key).setValue(YourValue);

Upvotes: 4

Related Questions