[英]Firebase Realtime Database obtain push() reference
This is how I save my Events in my app: 这是我将活动保存在应用中的方式:
FirebaseDatabase.getInstance().getReference().child("events").push().setValue(ev);
Now I would like each event to have its own chat room where users can send messages to each other. 现在,我希望每个事件都具有自己的聊天室,用户可以在其中相互发送消息。 However, I need to know the reference to the event so I can add the chat room.
但是,我需要知道对该事件的引用,以便可以添加聊天室。 I don't want to change the Event object to have this property.
我不想更改Event对象以具有此属性。 How do I do that?
我怎么做?
databaseRef = FirebaseDatabase.getInstance().getReference().child("events").child(?);
You can reference the pushed event using DatabaseReference#getKey()
, so to retrieve the newly added event, call: 您可以使用
DatabaseReference#getKey()
引用推送事件,因此要检索新添加的事件,请调用:
String eventId = FirebaseDatabase.getInstance().getReference().child("events").push()
.getKey()
Then you can do: 然后,您可以执行以下操作:
FirebaseDatabase.getInstance().getReference().child("events").child(eventId)...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.