How to simulate killing activity to conserve memory?

后端 未结 8 1760
清酒与你
清酒与你 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:03

    You can't do it in an automated way b/c its completely non deterministic.

    See my answer here: https://stackoverflow.com/a/15048112/909956 for details.

    But good news is that all you need to do is just simulate calling onSaveInstanceState and you are indirectly testing this low memory situation.

    onSaveInstanceState can be triggered by:

    1. losing focus (by pressing home which in essence is like switching from your app to launcher app), launching another activity, pressing recents
    2. changing orientation. this is the easier way if you are using an emulator
    3. changing developer setting: goto developer options --> Apps --> Don't keep activities. This is best option if you are testing temporarily on an actual device.

提交回复
热议问题