Tung Mai Le Tung Mai Le - 4 months ago 12
Android Question

In firebase, how do I retrieve the uid that was automatically created when pushing?

how do I retrieve the uid (automatically created) as the id of the object itself, so later I can find the object and update its child properties (if any). Thanks.

For example:

mFirebaseDatabaseReference.child(OBJ_CHILD).push().setValue(friendlyObject);
// I know this process will create a uid for the newly pushed object, and I want to get the uid of the bucket.

Answer

Try this:

ref = mFirebaseDatabaseReference.child(OBJ_CHILD).push();

... // create hashmap to push (friendlyObject)
ref.setValue(friendlyValue);

String uid = ref.getKey();

see more here - https://www.firebase.com/docs/android/guide/saving-data.html under
Getting the Unique ID Generated by push()

Comments