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

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


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.


This fixed the issue.

Override the onBackPressed() method of Landscape activity and set orientation to Portrait.

@Overridepublic void onBackPressed() {    super.onBackPressed();    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);}


Using intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) in previous Activity resolved my issue.