2

From this thread: https://groups.google.com/forum/#!msg/firebase-talk/ptTtEyBDKls/XbNKD_K8CQAJ

The behavior for addListenerForSingleValueEvent is: If we have cached data: raise an event with whatever we have cached (this may be stale). Send a request to the server to get the latest data. This means that you may get stale data in your event callback. You should get fresher data the next time you call addListenerForSingleValueEvent (since we'll have tried to update the cache).

We know this isn't ideal behavior and are looking into ways to improve it. For now, using keepSynced() is a good approach to make sure it's as fresh as possible.

Is this still the case in 2020? I have found that depending on a listener (at least ChildEventListener) has not been reliable when the app goes to the background or the device goes to sleep - hence I can't simply rely on keepSynced(true).

In my own testing of using addListenerForSingleValueEvent it seems to work consistently, but I need to be sure of this 100% on behalf of my users. I found this thread that describes a workaround using a Query object: https://stackoverflow.com/a/38129967/5147164

Is that workaround still required in 2020? Thank you.

policenauts
  • 512
  • 6
  • 18

0 Answers0