Search code examples
androidscreen-orientation

why horizontal application create vertical activity after onPause()


My app is supposed to be only horizontal. In AndroidManifest.xml I have android:screenOrientation="sensorLandscape".
But when I press Power button (turn off device) and then press Power button again (turn on device) I can see some problems. By debug process I can see that my application goes through the following steps:

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.



Where is my mistake? Should I set screen size at first anywhere?

I understood the problem: when I press Power button orientation is changed(lock screen is in portrait by default) which is causing calling onCreate().
So what should I do?


Solution

  • Using android:configChanges="orientation|screenSize" solved the problem. A piece of cake.