Denis Banach Denis Banach - 1 year ago 166
Android Question

Close Firebase database connection when leaving Android app

I made an Android app which receives realtime data from Firebase database. In my main Activity the user has to log in with e-mail and password and by success it opens a new Activity, which receives data.

It seems to be, that when the user leaves my app, the Firebase connection is still established. That is not good for the battery.

How is the way to manage the connection for closing and reopen the app? I think I need to use

. I found something like
, but I cannot found this method in the new Firebase.

Answer Source

Yes, you may use the activity lifecycle methods like onPause(), onStop() on onDestroy() to close your connection.

Also, it seems Firebase still has a goOffline() method -

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download