Changing Orientation, losing all my list items

前端 未结 3 864
醉酒成梦
醉酒成梦 2021-01-01 20:36

While I tested my application on an Android Device turning my Android phone from landscape to portrait, results in all the list items in my list view are disappearing.

3条回答
  •  天涯浪人
    2021-01-01 21:24

    The simplest way is to use onSaveInstanceState, explained in Janusz's answer.

    However, if there are many items in your list, saving them into a Bundle in onSaveInstanceState could slow down the Activity recreation process, which the users would experience as a lag. To save relatively large data, use onRetainNonConfigurationInstance, then reload data in onCreate with getLastNonConfugurationInstance.

提交回复
热议问题