How to test code built to save/restore Lifecycle of an Activity?

后端 未结 5 1465
醉话见心
醉话见心 2020-12-13 09:01

How can I test all of the following methods code? I want to play scenarios when all of them are happening to see if my code works for save/restore process of an activity. So

5条回答
  •  青春惊慌失措
    2020-12-13 09:17

    To test onSaveInstanceState and onRestoreInstanceState you can use either the SetAlwaysFinish tool (see link below) or the DevTools app included with the emulator.

    http://bricolsoftconsulting.com/how-to-test-onsaveinstancestate-and-onrestoreinstancestate-on-a-real-device/

    Both of these apps use a hidden setting called AlwaysFinish which is part of the ActivityManagerNative class to change the behavior of the Android OS. Under the new behavior, the OS will unload any activity as soon as it leaves the screen, triggering the onSaveInstanceState event. When the OS wants to bring the activity back, it will call the onRestoreInstanceState event.

    The link above explains how to use the SetAlwaysFinish app to test your app's onSaveInstanceState and onRestoreInstanceState events. If you want to use the DevTools, then enable Development Settings > Immediately destroy activities.

提交回复
热议问题