How do i put apps on sleep while my game is running in an Android Device. I m a Game Developer (intermediate Level). And i Wanna know the Can i put apps of phone running in background to sleep to free some ram and make my game run on 1 gb of phone smoothly (Android 9).

  • \$\begingroup\$ Why not try using less ram yourself \$\endgroup\$ – ratchet freak Feb 18 '20 at 12:20
  • \$\begingroup\$ as u know a user got 2gb of ram 1.1 or more is consume by android 8 8.1 9 10 +background apps like map other sevices etc takes upto 400 gb and users app also need some ram to continue there services like whatsapp which is running in background these apps can taike upto 200 mb of ram and i got only 100 mb of ram to run my game on those devices \$\endgroup\$ – Ali Raza Feb 18 '20 at 12:35
  • \$\begingroup\$ @AliRaza that's not how ram works. \$\endgroup\$ – Joe Swindell Feb 18 '20 at 19:53
  • \$\begingroup\$ please teach me i would love to know :) \$\endgroup\$ – Ali Raza Feb 19 '20 at 4:29
  • \$\begingroup\$ Choosing which apps should sleep or be evicted from RAM to make room for others is the job of the OS. Your game is likely not permitted to interfere in its decisions (otherwise they'd have to content with every app trying to evict every other one, to the detriment of the user experience when switching apps) \$\endgroup\$ – DMGregory Mar 12 '20 at 16:12

The OS on android devices handles this automatically when there is a need for more memory.

Specifically, what you are referring to sleep is moving apps to a standby state where they unload all data caches. After a second pass they will automatically save their data and state so they can shut down all tasks except background listeners and reopen later.

You have no control over this mechanism beyond taking up memory.

If your application is slowing down to declare more memory, try to load as much of the assets and metadata on initial scene load instead of in real time during gameplay. This should resolve most of your issues issues regarding memory heap footprint growth.

Any temporary variable (such as incrementing counters on loops) that will not last longer than the time in the function that creates it should be declared TLAB as to not be allocated from the main heap. This will further reduce memory heap growth.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.