FirebaseDatabase offers two methods to take a client offline:
DatabaseReference.goOffline()
Manually disconnect the Firebase Database client from the server and disable automatic reconnection. Note: Invoking this method will impact all Firebase Database connections.
FirebaseDatabase.goOffline()
Shuts down our connection to the Firebase Database backend until goOnline() is called.
A call to FirebaseDatabase.getInstance().goOffline()
produces the expected results:
ValueEventListener
for ".info/connected" fires for the disconnectOnDisconnect
action executesValueEventListener
s for remote changes do not fire, those for local changes doCompletionListener
s do not fireA call to DatabaseReference.goOffline()
seems to have no effect. None of the behavior listed above occurs. Is it broken? If not, how does it differ from the other goOffline()
?
When you enable disk persistence, your app writes the data locally to the device so your app can maintain state while offline, even if the user or operating system restarts the app. You can enable disk persistence with just one line of code.
Cloud Firestore supports offline data persistence. This feature caches a copy of the Cloud Firestore data that your app is actively using, so your app can access the data when the device is offline. You can write, read, listen to, and query the cached data.
Cloud Firestore is Firebase's newest database for mobile app development. It builds on the successes of the Realtime Database with a new, more intuitive data model. Cloud Firestore also features richer, faster queries and scales further than the Realtime Database. Realtime Database is Firebase's original database.
When you initialize Firestore, you can enable or disable offline persistence: For Android and Apple platforms, offline persistence is enabled by default.
This was an oversight in the 9.x release. FirebaseDatabase.getInstance().goOffline()
/ goOnline()
are the correct methods to use and DatabaseReference.goOffline()
/ goOnline()
are indeed broken and will be removed in a future release. Sorry for the confusion!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With