I'm trying to understand the differences between setting screenOrientation
on my manifest file like this
<activity android:name='.MainActivity' screenOrientation='portrait'/>
versus doing it during it's onCreate
part of the lifecycle like this
`setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);`
As I understand it, the first method will create activities in Portrait Mode regardless of phone orientation at the moment of creation (Meaning that the activity will be created in portrait mode even if you hold the phone in landscape) while the second one will create the activity in a configuration given by the phone orientation and then change (So, if you hold the phone in Landscape position and create an activity, you'll see the activity created on landscape, and then reconfigure itself to portrait mode).
Am I correct ? If I am not, can anyone explain to me exactly what the differences are ?
What you set in manifest is kind of initial value, which can be manipulated using setRequestedOrientation() method.
You can test what you have written by implementing a very simple app.
Basically you will get the same result. The difference is that orientation defined in manifest takes effect from the very beginning, creation of the activity.
Whereas you can call setRequestedOrientation() method to set it programmatically depending on conditions or events. For example you can change orientation from portrait to landscape on a button click using setRequestedOrientation() method. Or make it sensor dependent by passing argument ActivityInfo.SCREEN_ORIENTATION_SENSOR.