I see a lot of tutorials, documentation and questions about using the Firebase Realtime Database on Android talk about the addListenerForSingleValueEvent
method. This method reads the value from the database once, which is what I want to do.
But in the auto-complete in my IDE and in the documentation I also see a method called get()
, which also seems to read a value from the database once. From the name and signature it seems simpler, and more modern (as it returns a Task
). But since the other method is mentioned so much more, I want to make sure I’m using the right code.
So what is the difference between get()
and addListenerForSingleValueEvent
, why is the latter mentioned so much more in documentation, tutorials and questions, and which one should I use when I want to read a value from the database once?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…