2016-07-10 5 views
1

どのようにしてオブジェクト自体のIDとしてuid(自動的に作成された)を取得するのですか?そのため、後でオブジェクトを見つけてその子プロパティ(存在する場合)を更新できます。ありがとう。例えばfirebaseでは、押したときに自動的に作成されたuidをどのように取得できますか?

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. 

答えて

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
関連する問題