Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Two Methods for FirebaseDatabase Client Offline?

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:

  1. ValueEventListener for ".info/connected" fires for the disconnect
  2. OnDisconnect action executes
  3. ValueEventListeners for remote changes do not fire, those for local changes do
  4. CompletionListeners do not fire

A 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()?

like image 285
Bob Snyder Avatar asked Jun 01 '16 14:06

Bob Snyder


People also ask

What is offline data persistence?

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.

Can firebase be used offline?

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.

What is the difference between cloud firestore and realtime database?

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.

Is firestore offline?

When you initialize Firestore, you can enable or disable offline persistence: For Android and Apple platforms, offline persistence is enabled by default.


1 Answers

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!

like image 89
Michael Lehenbauer Avatar answered Oct 13 '22 08:10

Michael Lehenbauer