Android Pie adds feature to prevent killing RAM-heavy games if you accidentally exit

We may earn a commission for purchases made using our links.

Earlier today, Google officially announced Android Pie for the Google Pixel and Google Pixel 2. Immediately afterward, Essential released the Android 9 update for the Essential Phone. Other devices that participated in the Android P beta program should soon receive the update, so users who skipped the Developer Previews now have a lot of catching up to do. As we dig into the latest release including the source code drop on AOSP and the latest Compatibility Definition Document (CDD), we’ll be periodically updating you with any new information we uncover. Something interesting we found in the CDD is a section for “heavyweight” (RAM-heavy) apps and games wherein Android Pie will prioritize keeping these apps in RAM should the user accidentally exit them.

“Heavyweight” Apps and Games in Android Pie

A new section has been added to the CDD that outlines this feature. Here’s what it says:

3.17. Heavyweight Apps If device implementations declare the feature FEATURE_CANT_SAVE_STATE, then they: [C-1-1] MUST have only one installed app that specifies cantSaveState running in the system

at a time. If the user leaves such an app without explicitly exiting it (for example by

pressing home while leaving an active activity the system, instead of pressing back with

no remaining active activities in the system), then device implementations MUST

prioritize that app in RAM as they do for other things that are expected to remain running,

such as foreground services. While such an app is in the background, the system can still

apply power management features to it, such as limiting CPU and network access.

at a time. If the user leaves such an app without explicitly exiting it (for example by pressing home while leaving an active activity the system, instead of pressing back with no remaining active activities in the system), then device implementations MUST prioritize that app in RAM as they do for other things that are expected to remain running, such as foreground services. While such an app is in the background, the system can still apply power management features to it, such as limiting CPU and network access. [C-1-2] MUST provide a UI affordance to chose the app that won’t participate in the normal

state save/restore mechanism once the user launches a second app declared with

cantSaveState attribute.

state save/restore mechanism once the user launches a second app declared with cantSaveState attribute. [C-1-3] MUST NOT apply other changes in policy to apps that specify cantSaveState, such as

changing CPU performance or changing scheduling prioritization. If device implementations don’t declare the feature FEATURE_CANT_SAVE_STATE , then they: [C-1-1] MUST ignore the cantSaveState attribute set by apps and MUST NOT change the app

behavior based on that attribute.

Basically, this means is that, if a device supports the FEATURE_CANT_SAVE_STATE feature, then they must prioritize keeping in RAM the running app that specifies the cantSaveState attribute. This RAM prioritization kicks in if the user exits the app or game by pressing the home button or leaving the app or game without explicitly exiting it (like with a back button press or a quit button.) Furthermore, the system can still save power by limiting CPU and network access on those apps, but they just can’t free up RAM by killing them unless it’s necessary. Lastly, note that only one app with the cantSaveState attribute defined is allowed to be running. If you attempt to launch another app with this attribute defined while another is running, Android Pie will ask you to pick which game you want to keep running.

13) If a "heavy weight" app like a game is eating up too much memory, it looks like P has a warning box telling you to choose one app or the other. I triggered the dialog box manually to see what it looks like. pic.twitter.com/aa5lqGuwnB — Mishaal Rahman (@MishaalRahman) May 13, 2018

You can check whether your device supports FEATURE_CANT_SAVE_STATE by running the following two commands via ADB:

adb shell dumpsys package | grep "cant_save_state"

To check whether an app specifies the cantSaveState attribute will need decompiling the app and looking at its manifest or using the dumpsys package package.name.here command in ADB shell. Keep in mind that this attribute was only just added in API level 28 (Android 9 Pie) so it’s unlikely that many apps or games will be taking advantage of this just yet.

This feature will be incredibly useful for devices with small amounts of RAM and/or apps that eat up a ton of RAM. For instance, Fortnite Mobile on Android requires a minimum of 3GBs of RAM because of how much RAM it eats up (without even launching a game, Fortnite Mobile was reserving 1.6GBs of RAM on my Google Pixel 2 XL.) If Fortnite were to target SDK level 28 and use this feature, then this means that accidentally exiting the game will hopefully prevent it from being killed immediately if your device is running low on free RAM. Unfortunately, Fortnite only targets SDK level 21 at this time (Android 5.0 Lollipop) so it sadly does not take advantage of the latest APIs that Google offers in Android Pie, let alone Android Oreo, Android Nougat, or Android Marshmallow. Hopefully, other games update to take advantage of this feature. By next year, Google will require them to update if they want to be able to continue submitting updates on the Google Play Store.