How to simulate killing activity to conserve memor

2019-01-23 22:54发布

Android doc say:

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

But how to simulate this situation?I want to debug the onRestoreInstanceState(Bundle) method,but don't know how to.

8条回答
Rolldiameter
2楼-- · 2019-01-23 23:38

Use the SetAlwaysFinish app (works on a real device and in the emulator) or use the Google DevTools app (works in the emulator only).

These apps use the hidden AlwaysFinish setting of the ActivityManagerNative class to change the behavior of the OS and cause it to immediate unload every activity as soon as it's no longer in the foreground. This will reliably trigger the onSaveInstanceState and onRestoreInstanceState events.

See link below for more details: http://bricolsoftconsulting.com/how-to-test-onsaveinstancestate-and-onrestoreinstancestate-on-a-real-device/

查看更多
何必那么认真
3楼-- · 2019-01-23 23:40

There's a decent solution for this in Android 6 and newer. See my answer here: Simulate killing of activity in emulator

查看更多
登录 后发表回答