Firebase Realtime Database Addvalueeventlistener
Solution 1:
When you attach a listener with addValueEventListener()
and the data is available in the local disk cache, the onDataChange()
method will immediately fire with the data from the cache.
The Firebase client will then register with the server for updates to the data. Any time it receives updated data, it will invoke onDataChange()
again.
So if you have stale data in your local disk cache, you may receive two calls to onDataChange()
in "quick" succession: one with the stale data and the second one with the latest data. There is currently no way to see whether the data is stale or not.
The only time when this really creates a tricky situation is when you use addListenerForSingleValueEvent()
. Since you will only get the first onDataChange()
event there, you may only get the stale data. This is one of the reasons that we recommend not to mix disk persistence with single-value event listeners.
Post a Comment for "Firebase Realtime Database Addvalueeventlistener"