本文介绍了Firebase DatabaseReference vs DataSnapshot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我不太明白什么时候应该使用DatabaseReference和DataSnapshot。 在我的应用程序中,我似乎没有真正区别使用它们(可能除了写入到Firebase,在这种情况下DataSnapshot没有被创建)。 解决方案 DatabaseReference是所有数据库操作的起点。这允许您读取,写入和创建新的DatabaseReferences。 DataSnapshot是在Firebase位置上高效生成的不可变数据副本。他们不能被修改,永远不会改变。 我相信,在DataSnapshot下创建一个比DatabaseReference更安全的对象,在一个只读的情况下,因为这将是一个不可变的对象,没有任何额外的数据附加到它像DatabaseReference。 来源: DatabaseReference https://firebase.google.com/docs/reference/android/com/google/firebase/database/DatabaseReference DataSnapshot https://firebase.google.com/docs/reference / android / com / google / firebase / database / DataSnapshot I did not quite understand when should I use DatabaseReference and when DataSnapshot.In my application I seem to be using both of them without real distinction (maybe except for writing to Firebase in which case DataSnapshot was not made for). 解决方案 A DatabaseReference is a starting point for all database operations. This allows you to read, write, and create new DatabaseReferences.A DataSnapshot is an efficiently-generated immutable copy of the data at a Firebase Location. They cannot be modified and will never change.I believe that under the hood, the DataSnapshot would be a more efficient object to create than a DatabaseReference and a safer object to work with in a read-only scenario as this would be an immutable object without any extra data attached to it like the DatabaseReference.Sources:DatabaseReferencehttps://firebase.google.com/docs/reference/android/com/google/firebase/database/DatabaseReferenceDataSnapshothttps://firebase.google.com/docs/reference/android/com/google/firebase/database/DataSnapshot 这篇关于Firebase DatabaseReference vs DataSnapshot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-15 10:34