Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 8.1 screen orientation issue: flipping to landscape a portrait screen

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.

  1. Sometimes goes to portrait then to landscape and stay on landscape.
  2. Sometimes goes to portrait then to landscape and finally portrait again.

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

like image 963
Sol Avatar asked Nov 10 '17 17:11

Sol


People also ask

How do I force horizontal orientation on Android?

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.

How do I fix the orientation on my Android phone?

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.

How do you reverse landscape on Android?

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.

What happens when screen orientation changes in Android?

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.


1 Answers

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.

like image 135
thetestspecimen Avatar answered Sep 21 '22 11:09

thetestspecimen