0

I am developing an app having one activity have two different views for Landscape and Portrait mode. Everything fine on handling orientation but the problem is that I want to show Landscape mode first and then user can change orientation to portrait later whether previous activity is in Portrait mode.

when I am forcefully defining orientation to landscape in manifest or by calling in onCreate setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); then method onConfigurationChanged

@Override
    public void onConfigurationChanged(Configuration newConfig) {
        // TODO Auto-generated method stub
        super.onConfigurationChanged(newConfig);
    }

not being called.

I have also defined

android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"

in Manifest .

Any help will appreciable.

Neha Shukla
  • 3,572
  • 5
  • 38
  • 69
Ravi Kant
  • 820
  • 6
  • 13
  • "show landscape mode first and then user can change orientation to portrait later." So, user is in portrait mode, activity starts landscape. And if they want portrait, they need to rotate device twice? What a nonsence – Alexander Zhak Sep 02 '14 at 10:44
  • manually setting orientation to landscape locks orientation changing, so onConfigurationChanged method not getting called. – Ravi Kant Sep 02 '14 at 12:22

1 Answers1

0

Try this alternative option using a OrientationEventListener in your Activity code:

private OrientationEventListener orientationEventListener;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    orientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) {

        @Override
        public void onOrientationChanged(int orientation) {

            // ....

        }
    };

    if (orientationEventListener.canDetectOrientation()) {
        orientationEventListener.enable();
    }

}

@Override
protected void onDestroy() {
    super.onDestroy();
    orientationEventListener.disable();
}
sergiomse
  • 775
  • 12
  • 18