Sagar Trehan Sagar Trehan - 2 months ago 18
Android Question

When opening app while keeping device in landscape mode then, on Portrait activity dialog is showing landscape orientation

As per product requirement I have to keep the orientation of app to portrait for mobile and landscape for tablet.
Used following code to set orientation for each activity in

onCreate()
callback before invoking
super.onCreate()


public static void updateOrientation(Activity activity) {
boolean hasAPI18 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2;
if (isTablet()) {
activity.setRequestedOrientation(hasAPI18 ? ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
} else {
activity.setRequestedOrientation(hasAPI18 ? ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}


Working scenario For Mobile:


  1. Keep device in portrait orientation

  2. Open application

  3. Do event to show dialog



Result: On portrait activity, Dialog show properly in portrait mode.

Error scenario For Mobile:


  1. Keep device in landscape orientation

  2. Open application

  3. Do event to show dialog



Result: On portrait activity Dialog shows in landscapemode due to which only 2/3 part of dialog is visible.

Verified:


  1. Activity orientation and window orientation is set to portrait while showing dialog on mobile.


Answer

To fix the issue I updated the supportLibraryVersion from 23.1.2 to 24.1.1. I am not sure about the root cause. I checked release note of supportLibrary but didn't any bug fixed related to this one. But updating support library version helped me to fix it. Hope it would help someone

Comments