Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
358 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...