Simulate low battery & low memory in Android
To trigger your onTrimMemory
callbacks:
adb shell am send-trim-memory <process-name> <level>
e.g. adb shell am send-trim-memory com.example.app MODERATE
Low memory can also be simulated using Background process limit
under the device developer options.
Go to Settings > Developer options
. Under the app
section change the Background process limit
to No background processes
Now your activity will be killed every time you switch to another app. Useful for testing state saving and state restoration.
yes, this api triggers the same callback you would get if you registered a context to ComponentCallback2, specifically the ComponentCallback2#onTrimMemory this wasn't mentioned here, so I thought I'd make it clear. The syntax for this command is:
am send-trim-memory [--user <USER_ID>] <PROCESS> [HIDDEN|RUNNING_MODERATE|BACKGROUND|RUNNING_LOW|MODERATE|RUNNING_CRITICAL|COMPLETE]
Note: this command is only available on devices running Marshmallow+