qbix qbix - 3 months ago 20
Android Question

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. ValueEventListener
    s for remote changes do not fire, those for local changes do

  4. CompletionListener
    s 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()
?

Answer

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!

Comments