Firebase GetValue

I am using firebase to store and retrieve data from the cloud. However I found that even if a take my device offline, I can still get result from “GotValue” event.

Example:

  1. Uncheck “Persist” of firebase component in design mode
  2. Run app, get device online, use “GetValue” to retrieve data from cloud
  3. Switch device to offline, make a few updates using “StoreValue” and “AppendValue”
  4. Check firebase console, no update to data in cloud (as expected)
  5. Keep device offline, use “GetValue” retrieve data, “GotValue” triggered with data as normal, no error detected (including updates in step 3)

Does firebase work like that? If that’s the case, how can I detect if my local copy synchronized with the cloud?

see the documentation http://ai2.appinventor.mit.edu/reference/components/experimental.html#FirebaseDB

Persist
If true, variables will retain their values when off-line and the App exits. Values will be uploaded to Firebase the next time the App is run while connected to the network. This is useful for applications which will gather data while not connected to the network. Note: AppendValue and RemoveFirst will not work correctly when off-line, they require a network connection.

Note: If you set Persist on any Firebase component, on any screen, it makes all Firebase components on all screens persistent. This is a limitation of the low level Firebase library. Also be aware that if you want to set persist to true, you should do so before connecting the Companion for incremental development.

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.

Thanks Taifun. I read that before. To my understanding, if I uncheck “Persist”, it should be “false” and data should not be available when offline. Did I get it wrong?

What I actually want to achieve is to detect and resync data before making any update to the dataset in firebase (as I want to do some calculation based on the most-updated set of data) in case the data on the device is outdated (perhaps due to sleep mode…). That’s why I uncheck “Persist” and expect that firebase may return error or keep waiting for “GotValue” event triggered if the device somehow goes offline.

I don’t know… we have to wait for someone else to answer this question…

Taifun