N Sharma
N Sharma

Reputation: 34477

Android: onConfigurationChanged() is not calling on change in Orientation

I have a activity in which when i change the orientation then onConfigurationChanged() is not called.

Please help me to sort out this issue. I tried but could not find the reason for this.

Code:

@Override
public void onConfigurationChanged(Configuration configure){
    super.onConfigurationChanged(configure);
    setLayout(); //Set the layout.

    //Get the orientation of the device and set the gravity according to that.
    if(configure.orientation == Configuration.ORIENTATION_PORTRAIT) {
        parentLinearLayout.setGravity(Gravity.CENTER_VERTICAL);
    } else if(configure.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        parentLinearLayout.setGravity(Gravity.CENTER_HORIZONTAL);
    }
}

<activity android:name=".AddProductsActivity" 
    android:configChanges="orientation|keyboardHidden"/>

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

Upvotes: 3

Views: 7488

Answers (1)

Avadhani Y
Avadhani Y

Reputation: 7626

If you are targeting API 13 or higher, you have to add screenSize.Please change this line:

android:configChanges="orientation|keyboardHidden"

to

android:configChanges="orientation|screenSize|keyboardHidden"

Upvotes: 18

Related Questions