Home > Enterprise >  Datasnapshot is not updated even when connected to internet in my workermanager
Datasnapshot is not updated even when connected to internet in my workermanager

Time:03-10

With debugging I can see that it enters all of that but snapshot has an old value. I have persistency enabled in firebase database. What's wrong?

This is my code of the worker class inn which I save in Shared preferences some data. But for example it enters ref1 but snapshot has the old value.

code

Is it not necessary to look at the details (data input, ..., job inside worker, etc).

CodePudding user response:

If you have disk persistence enabled and there is a value stored in the local cache, the onDataChange of a listener registered with addValueEventListener will be called twice:

  1. Right away with the current value from the local cache.
  2. Then again once the latest value is retrieved from the server.

There is no way to change this behavior of addValueEventListener. to skip #1

If you want to get the value from the server, and only fallback to the disk cache if the server isn't available, consider using the newer get() operation that does precisely that.

  • Related