firebaser here
Great question!
If there is no active action, the operating system can close the connection to the Firebase database at any time. Our SDKs do not try to prevent this, but will reconnect when the application is activated again.
What you describe in your second paragraph is what we call push to sync, where you send a push notification (usually a quiet FCM data message) to initiate data synchronization.
We did something similar in the I / O application last year, and although it was a little more complicated than we wanted, it worked great. We explicitly controlled the connection in this case by calling goOnline() and goOffline() (after 5 minutes iirc). The main synchronization code can be found in the IOSched github repo .
source share