I'd like to have all activities in portrait orientation.
So I have tried both
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
in onCreate(), onPause() or onResume()
but the screen will flip to landscape and back to portrait in case of I rotate device in landscape from the beginning before opening the app.
But if I remove setRequestedOrientation
method and just add android:screenOrientation="portrait"
in AndroidManifest.xml
only then it works (but let's imagine if I have 30 activities so it's better to have in BaseActivity instead)
How to reproduce
BaseActivity has method in
onCreate(), onResume(), onPause() setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Rotate device in landscape orientation.
- Open app, Activity A is flipping from landscape to portrait.
- Start Activity B from Activity A, Activity B is flipping from landscape to portrait.
Note I have checked already Android 8.1 screen orientation issue: flipping to landscape a portrait screen
Activity rotating itself and back to normal in android 8.1
but it didn't work (it works only if orientation is defined in AndroidManifest)
If someone knows how to fix please share the solution
Thank you so much.