2

My Activity onConfigurationChanged is not called at all. I have updated my SDK API to Marshmallow ;

In my code overwrite "onConfigurationChanged":

@Override
    public void onConfigurationChanged(Configuration newConfig) {
    Log.d(HomeActivity.class.getSimpleName() , "called"); // not called
    super.onConfigurationChanged(newConfig);
    Log.d(HomeActivity.class.getSimpleName(), "called"); // not called

In my Android Manifest I declared:

<activity
            android:name=".activities.HomeActivity"
            android:configChanges="layoutDirection|locale"

And i'm calling for changing language :

public void changeLocale(Locale locale) {
        Resources res = mContext.getResources();
        DisplayMetrics dm = res.getDisplayMetrics();
        android.content.res.Configuration conf = res.getConfiguration();
        conf.locale = new Locale(locale.toString().toLowerCase());
        res.updateConfiguration(conf, dm);
}

Does anyone know what changed or what I am doing wrong/missed ?

Thanks

A.AL
  • 135
  • 3
  • 12

3 Answers3

0

onConfigurationChanged() will only be called if the user changes the Locale (language) setting of the phone. Just calling Resources.updateConfiguration() does not trigger this.

David Wasser
  • 93,459
  • 16
  • 209
  • 274
0

Please remove android:configChanges="layoutDirection|locale"

Abhinav Singh Maurya
  • 3,313
  • 8
  • 33
  • 51
mdtuyen
  • 4,470
  • 5
  • 28
  • 50
0

Try adding this to the manifest under your activity

android:configChanges="keyboardHidden|orientation|screenSize"
suku
  • 10,507
  • 16
  • 75
  • 120