问题
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