How to simulate killing activity to conserve memory?

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

    To debug onRestoreInstanceState you could do the following:

    • make sure you can debug application right after its start (calling android.os.Debug.waitForDebugger() from your constructor helps, it hangs your application until debugger is connected),

    • put you application in some state,

    • causally kill it from Settings->Apps,

    • causally switch back to it through Recent Apps button (it will still be in the list),

    • at this moment your application will be started anew and onRestoreInstanceState will be immediately called on the top activity.

提交回复
热议问题