Android doc say:
\"When the system, rather than the user, shuts down an activity to conserve memory, ... \"
But how to simulate
For the purposes of debugging onRestoreInstanceState()
, just change the screen orientation ([Ctrl]-[F11] in the emulator). Your activity will be destroyed and recreated, and the onSaveInstanceState()
/onRestoreInstanceState()
pair will be invoked.
I've used the "Don't keep activities" developer option to reproduce a crash that happened when an activity was killed due to memory pressure. You can find it in the Apps
section of Settings->Developer Options
.
It destroys every activity as soon as you leave it. E.g. if you press home to put your app in the background the current activity is destroyed. See https://stackoverflow.com/a/22402360/2833126 for more information.