How to simulate killing activity to conserve memory?

后端 未结 8 1740
清酒与你
清酒与你 2020-12-15 15:22

Android doc say:

\"When the system, rather than the user, shuts down an activity to conserve memory, ... \"

But how to simulate

相关标签:
8条回答
  • 2020-12-15 16:22

    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.

    0 讨论(0)
  • 2020-12-15 16:26

    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.

    0 讨论(0)
提交回复
热议问题