在firebase中,如何检索推送时自动创建的uid?

时间:2016-07-10 18:34:08

标签: android firebase firebase-realtime-database

如何检索uid(自动创建)作为对象本身的id,所以稍后我可以找到该对象并更新其子属性(如果有的话)。谢谢。

例如:

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.

1 个答案:

答案 0 :(得分:2)

试试这个:

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

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

String uid = ref.getKey();

在此处查看更多内容 - Getting the Unique ID Generated by push()

下的https://www.firebase.com/docs/android/guide/saving-data.html