My Android Flutter app uses the AppLifecycleState to determine if the user is returning to the app. I have a stream set up from Firestore for new data from any document. But if the app is in the background, the stream eventually is paused. To fix this I make a call after AppLifecycleState.resumed
is triggered and make a separate call to fetch new data. The stream seems to resume after. Although, if the app sits in the background for an extended amount of time my app seems unresponsive. Agains this would be a couple of hours or so. Any idea on how to fix this?
Asked
Active
Viewed 269 times
1

temp_
- 1,238
- 2
- 12
- 24
-
Perhaps it's connected to this issue. I'm also looking for solution: https://github.com/FirebaseExtended/flutterfire/issues/4305 – Jacob Stachecki Apr 27 '21 at 11:40
1 Answers
0
When an app is no longer visible on screen, the host operating system will eventually pause, then kill the app's process, in order to free up resources for other things that need to happen on the device. The fact that your app seems unresponsive is because of this behavior, which your app should fully expect. Your app can not run forever.
If you want some ideas to work around this, start reading here: Flutter: cross-platform way to keep application running in the background

Doug Stevenson
- 297,357
- 32
- 422
- 441
-
I just want a way to refresh after it comes back to the foreground. The view itself seems to be alive but Firebase seems to have paused my stream and fetching new data seems to not work for at least a few seconds. – temp_ Apr 15 '20 at 16:49
-
It can take a while for Firestore to reestablish its connection and add the listener again. – Doug Stevenson Apr 15 '20 at 16:55
-
-
-
Would it be best practice to pause my streams when in the background and resume them when in the foreground? I'm just trying to reduce the lag I get when my app is in the foreground. – temp_ Apr 16 '20 at 20:50