Usually whenever my app is in the background it can be easily resumed and correctly executes the $ionicPlatform.on(“resume”) event. However on android (not on iOS) after a few hours in the background the app restarts instead of resuming when called again. Is this expected behavior to clear the memory every once in a while, or can it maybe be modified via
in AndroidManifest.xml? Somehow such a restart behavior (especially if login is involved) seems like alot of time waste, so i’m sure there should be a better option. any help appreciated, thanks!
Update (partially solved)
I figured out there is a preference called "alwaysRetainTaskState", which according to android documentation does the following:
Normally, the system clears a task (removes all activities from the stack
above the root activity) in certain situations when the user re-selects that
task from the home screen. Typically, this is done if the user hasn’t visited
the task for a certain amount of time, such as 30 minutes.
android:alwaysRetainTaskState=“true” restarts of the android app can be prevented in most cases.The app now still seems to restart every once in a while but much less often. For anyone who is interested in doing this in ionic/cordova, it’s a little tricky since any modification of AndroidManifest.xml will be overwritten when recompiling the app. The way I solved it was by adding the line
<preference name=“android-alwaysRetainTaskState” value=“true”>
to the android platform section of config.xml and using a hook to modify the manifest after build as described here https://gist.github.com/marcocarnazzo/6f01a57d390e8fe3071f