2

I added android:configChanges="density" for the activity in Manifest file. But I am not getting the onConfigurationChanged() callback

    <?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".ClientActivity" android:configChanges="density">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

I mentioned below the onConfigurationChanged() method. Actually I am not doing anything inside that one. If I get the call back I want to proceed further.

    @Override
public void onConfigurationChanged(Configuration newConfig)
{
    super.onConfigurationChanged(newConfig);
}
  • Can you post your onConfigurationChanged method implementation? – tomerpacific Dec 21 '18 at 07:08
  • Hello Tomerpacific, I added my onConfigurationChanged() method also. First of all I am not getting the callback. If I get the callback I will proceed further. Please check and help me. Thank you – Ravi Teja M Dec 21 '18 at 07:49

2 Answers2

1

add in manifest

android:configChanges="keyboardHidden|orientation|screenSize"

add in activity.

@Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            Log.d("OrientationMyApp", "Current Orientation : Landscape");

        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
        Log.d("OrientationMyApp", "Current Orientation : Portrait");
        // Your magic here for portrait mode
      }
   }
Pratik18
  • 365
  • 1
  • 7
  • Hello Pratik, Thanks for your reply. Actually I am changing the ScreenZoom. For that as I know android:configChanges="density" is the required property we need to add in Manifest. For only density I am not getting the callback. Can you please check and help me if you have any solution for this problem. Thank you – Ravi Teja M Dec 21 '18 at 07:51
  • android:configChanges you can add density option. – Pratik18 Dec 21 '18 at 07:58
  • Hello Pratik, I added density option already in the manifest. I mentioned the same code above. Even I am not getting the callback. – Ravi Teja M Dec 21 '18 at 08:05
  • newConfig.densityDpi using through get dpi – Pratik18 Dec 21 '18 at 08:43
0

I was having this same issue and it was driving me crazy, what fixed for me was adding smallestScreenSize:

android:configChanges="density|smallestScreenSize"

I already had screenSize|screenLayout|layoutDirection as well for other reasons, those might be necessary too. I would suggest experimenting with all the possible attributes for android:configChanges until it works.

https://developer.android.com/guide/topics/manifest/activity-element#config

Mina Tadros
  • 514
  • 6
  • 18