How to keep app open in background

I’m having an issue with one of my apps where the app sometimes closes after being in the background for an hour so it fully restarts the app. I did find this: but I’m worried this plugin will cause my app to always be running and drain my user’s batteries. Is that the case? If yes how should one go about keeping their app “paused” in the background allowing them to resume from where they left off?

One strategy would be to define an interface encapsulating what “app state” means for you and persisting an instance of it into Storage whenever it is modified. Then, on app startup, you can read it back from storage and restore it to whatever provider holds it during normal operation. Something I consider a major benefit of this approach is that it works regardless of whether the app was GCd by the OS (which is probably what you’re encountering as “sometimes closes”) or if the user explicitly quits the app.

1 Like