除了@Raghunandan 建议的内容之外,您还可以阅读有关重新创建活动的官方文档。它说:
Your activity will be destroyed and recreated each time the user rotates the screen. When the screen changes orientation, the system destroys and recreates the foreground activity because the screen configuration has changed and your activity might need to load alternative resources (such as the layout.
它还引入了
onSaveInstanceState()的概念(要保存有关活动状态的其他数据,您必须重写此方法)和
onRestoreInstanceState()方法(此方法的默认实现执行恢复之前已被冻结的任何视图状态onSaveInstanceState(捆绑))。
您还可以在此处使用 Save Instance State线程保存 Android Activity 状态查看这些方法的示例实现,这将帮助您保存和恢复状态。
更新
您也可以尝试使用:
<activity name= ".YourActivity" android:configChanges="orientation|screenSize"/>
说的文档;android:configChanges
It lists configuration changes that the activity will handle itself. When a configuration change occurs at runtime, the activity is shut down and restarted by default, but declaring a configuration with this attribute will prevent the activity from being restarted.
资料来源:如果状态由我的类组成,如何在 Android 中的方向更改期间保存状态?
希望这可以帮助。