Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onConfigurationChanged is not getting called any time in android

I have create sample program to test Orientation. If portrait mode and I tilt the phone the other way round I want my sample app to reversePortrait. After reading lot of questions on this - Figured we need to need use:

   onConfigurationChanged(Configuration newConfig) 

I was trying out the following:

    @Override
public void onConfigurationChanged(Configuration newConfig) 
{
    super.onConfigurationChanged(newConfig);

    Configuration c = getResources().getConfiguration();

    Log.e("Config",""+c);

    if (c.orientation == Configuration.ORIENTATION_PORTRAIT) 
    {
        // portrait

        Log.e("On Config Change","portrait");

    } 
    else if (c.orientation == Configuration.ORIENTATION_LANDSCAPE) 
    {
        // landscape
        Log.e("On Config Change","LANDSCAPE");

    }
}

manifest.xml

android:configChanges="orientation" 

tried even this

android:configChanges="orientation|screensize"

Strange I am not getting logs inside OnConfigurationChange method.

Not sure. What is the problem here?

I am using minimum api 8 to target Api 18.

Can somebody help me out with this?

Thanks!

like image 794
TheDevMan Avatar asked Jan 21 '26 16:01

TheDevMan


2 Answers

I had a same issue after changing target API to 19(4.4 kitkat) You need to add layoutDirection attribute for targeting higher than version 17.

my attribute looks like:

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

The key is to add 'layoutDirection'

like image 162
jclova Avatar answered Jan 25 '26 01:01

jclova


I just encountered this problem, and fixed it with this weird little trick.

Set your screenOrientation in your manifest, like so:

android:screenOrientation="sensor"

That fixed it for me.

like image 39
eoinzy Avatar answered Jan 25 '26 02:01

eoinzy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!