Losing connection to Firebase realtime database after leaving the app in the background for a while

Viewed 1703

My app loses connection to Firebase Realtime Database after being put in the background for a while ... In other words when I reopen my app again after being in the background for a while, Realtime Database services stop functioning until I clear the app data at the phone settings and everything back to normal ... I read about similar cases and found out that Android destroys resources (Socket connection) with Firebase after being put in the background for a specific period of time. However, there was no straightforward solution provided to restore connection after going back to the app ... so any help ?

1 Answers

It is expected that apps will lose their socket connections when there is no visible activity. That's the way the Firebase SDK works. Also, Android will aggressively pause background applications so they don't consume data and battery when the user isn't actively using it.

When an activity becomes started again, the Firebase SDK should attempt to restore the websocket it uses to communicate with the server. This websocket is fully managed by the SDK. You don't have to do anything to tell it to reconnect.

Related