Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cause Low Memory Condition on Android

How can I cause a Low Memory Condition on an Android device so that my Activity is destroyed and the associated Application class receives onTrimMemory() while my application is in the background. I am having issues in my app related to recovery from being killed by the Android OS, when in the background, and want to be able to step through the code in the debugger, but I can't regularly generate this condition, particularly when connected to the debugger :)

Thank You, Gary

like image 234
Gary Kipnis Avatar asked Sep 16 '25 05:09

Gary Kipnis


2 Answers

Another way to do it:
In your device:
Go to Settings -> Developer options and check "Dont keep activities".
This will kill your activity as soon it goes in the background.

like image 105
Lazy Ninja Avatar answered Sep 19 '25 13:09

Lazy Ninja


You can usually trigger this by throwing your app into the background, and then launching 10-20 apps (depending on the device). This will eventually cause your process to be terminated, which I would assume would be preceded by the onTrimMemory() callback.

like image 26
Kevin Coppock Avatar answered Sep 19 '25 14:09

Kevin Coppock