ChildEventListener和ValueEventListener Firebase接口有什么区别? [英] What is the difference between ChildEventListener and ValueEventListener Firebase interfaces?

查看:458
本文介绍了ChildEventListener和ValueEventListener Firebase接口有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些文档说,他们都在Firebase数据库位置监听更改。

他们做几乎相同的事情,尽管ChildEventListener有时可以更灵活:使用 ChildEventListener ,你可以为4个动作指定不同的行为( onChildAdded onChildChanged onChildMoved onChildRemoved ),而 ValueEventListener 仅提供 onDataChanged



另外,ChildEventListener在子级位置提供DataSnapshots(数据的不可变副本),而ValueEventListener提供整个节点的DataSnapshot。

The documentation says they both listen to changes at a Firebase database location.

解决方案

They do almost same thing, though ChildEventListener can be sometimes more flexible: with ChildEventListener you can specify different behavior for 4 actions (onChildAdded, onChildChanged, onChildMoved and onChildRemoved), while ValueEventListener provides only onDataChanged.

Also ChildEventListener provides DataSnapshots (immutable copies of the data) at child's location while ValueEventListener provides a DataSnapshot of a whole node.

这篇关于ChildEventListener和ValueEventListener Firebase接口有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆