为什么水平应用程序在 onPause() 之后创建垂直 activity
why horizontal application create vertical activity after onPause()
我的应用程序应该只是水平的。在 AndroidManifest.xml 我有 android:screenOrientation="sensorLandscape"
。
但是当我按下电源按钮(关闭设备)然后再次按下电源按钮(打开设备)时,我发现了一些问题。通过调试过程,我可以看到我的应用程序经历了以下步骤:
press Power button->onPause()->onSaveInstance()->onStop()->onDestroy()->onCreate()->onStart()->onResume()->onPause(). And I can see that HORIZONTAL activity was created but its size is equal to vertical screen!
Then:
press Power button->onResume()->onPause()->onSaveInstante()->onStop()->onDestroy()->onCreate()->onStart()->onResume().
And needed HORIZONTAL activity was created.
我的错误在哪里?我应该首先在任何地方设置屏幕尺寸吗?
我理解问题所在:当我按下电源按钮时方向发生改变(锁定屏幕默认为纵向),导致调用 onCreate()。
那我该怎么办呢?
使用android:configChanges="orientation|screenSize"解决了问题。小菜一碟。
我的应用程序应该只是水平的。在 AndroidManifest.xml 我有 android:screenOrientation="sensorLandscape"
。
但是当我按下电源按钮(关闭设备)然后再次按下电源按钮(打开设备)时,我发现了一些问题。通过调试过程,我可以看到我的应用程序经历了以下步骤:
press Power button->onPause()->onSaveInstance()->onStop()->onDestroy()->onCreate()->onStart()->onResume()->onPause(). And I can see that HORIZONTAL activity was created but its size is equal to vertical screen!
Then:
press Power button->onResume()->onPause()->onSaveInstante()->onStop()->onDestroy()->onCreate()->onStart()->onResume(). And needed HORIZONTAL activity was created.
我的错误在哪里?我应该首先在任何地方设置屏幕尺寸吗?
我理解问题所在:当我按下电源按钮时方向发生改变(锁定屏幕默认为纵向),导致调用 onCreate()。
那我该怎么办呢?
使用android:configChanges="orientation|screenSize"解决了问题。小菜一碟。