user6650650 user6650650 - 2 months ago 26
Android Question

Firebase real time data listener

I have a question about Firebase Database. After data has been changed , does the listener give you whole data again or just the recently added data?


The documentation says:

You can use the onDataChange() method to read a static snapshot of the contents at a given path, as they existed at the time of the event. This method is triggered once when the listener is attached and again every time the data, including children, changes. The event callback is passed a snapshot containing all data at that location, including child data. If there is no data, the snapshot returned is null.

So also the unchanged parts of the data are returned.

This just means that you should use as specific and narrowed-down listeners as possible, as the documentation also suggests:

Important: The onDataChange() method is called every time data is changed at the specified database reference, including changes to children. To limit the size of your snapshots, attach only at the highest level needed for watching changes. For example, attaching a listener to the root of your database is not recommended.