I have all activities in portrait mode except the one that I use to play a video that is always landscape. I found that on Android 8.1 every time I open the video activity and close it the previous activity go to landscape even it's set to "portrait" on the manifest.
This is only happening when a go back from a activity that it's landscape.
There is anyone who is experiencing this?
Thanks.
EDIT
I report the bug on Google: https://issuetracker.google.com/issues/69168442
EDIT 2
It seems fixed on Android 9
Open the AndroidManifest. xml and add the following android:screenOrientation="landscape" e.g. Show activity on this post. To do this at the Activity level, in case you want to change it dynamically or allow the user to select the orientation, use setRequestedOrientation in your Activity's onCreate method.
To do this, swipe down from the right side of the top panel. Hold the device in the orientation in which you want it locked. On the drop-down menu, touch the “Auto Rotate” button. The “Auto Rotate” button becomes the “Rotation Locked” button.
Unfortunately Android doesn't allow creating a separate layout for landscape-reverse (like we can do for portrait and landscape with layout-land and layout-port ). AFAIK, the only way is to change the activity-xml from java code.
When you rotate your device and the screen changes orientation, Android usually destroys your application's existing Activities and Fragments and recreates them. Android does this so that your application can reload resources based on the new configuration.
Just came across this problem in my own app.
The solution that works for me is as follows:
onCreate(){ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } onPause(){ if (android.os.Build.VERSION.SDK_INT >= 27) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } } onResume(){ if (android.os.Build.VERSION.SDK_INT >= 27) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } }
The above code should go in the activity that is in landscape mode (i.e. the second activity, and the one you press the back button from)
I would like to point out that this solution was not my own, and I have taken it from the #20 post at the following link (which is also noted in the OP):
https://issuetracker.google.com/issues/69168442
I just thought it might be easier for people to access if they don't have to search another page for it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With