Android screen orientation issue in 8.1.0

ぐ巨炮叔叔 提交于 2019-12-11 05:07:00

问题


Am having issue in Android OS 8.1.0

  • Start a portrait activity (portrait declare on manifest)
  • Start a landscape activity (landscape declare on manifest)
  • Finish the landscape activity
  • Portrait activity is showed again but the orientation start flipping: first in portrait mode, then landscape mode and finally portrait again.

I had observed this issue in google pixel 2 xl device with OS version 8.1.0 onwards ( issue present in Android P developer preview1 also)

i saw someone posted in google groups also

https://issuetracker.google.com/issues/69168442

but didn't get any fix, how can i fix this issue.?

My application is hybrid application (cordova) , I also tried to replicate issue in native android but issue is not there in native android sample app


回答1:


Yes, This is an issue in Android 8.1 OS version. As this was made obsolete. we can have a work around for these kind of issues. In this particular API level , Android OS might be storing the latest orientation value and is being applied to all the screens until the previous screen or that particular screen is destroyed. So, the work around for this type of issue is to change the orientation before going back to the screen . for ex: If ScreenA is in portrait mode and screenB is in landscape mode and if screen is moved to ScreenB which is Landscape and if you come back to ScreenA without killing ScreenB (restoring ScreenA), screenA also be visible in Landscape. To fix this issue, force change the orientation of ScreenA to Portrait in onPause() or OnStop() of ScreenB(to restore ScreenA).

if (android.os.Build.VERSION.SDK_INT >= 27) {
         setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

after this call, ScreenA will be in portrait. Also, in onResume() of ScreenB,

if (android.os.Build.VERSION.SDK_INT >= 27) {
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}


来源:https://stackoverflow.com/questions/49293016/android-screen-orientation-issue-in-8-1-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!