title: Change language programmatically (Android N 7.0 - API 24)
body: <p>I'm using the following code to set specific language in my app. Language is saved into <code>SharedPreferences</code> within the app. <strong>And it works perfectly up to API level 23.</strong> With Android N <code>SharedPreferences</code> works well too, it returns the correct language code-string, but it does not change the locale (sets default language of the phone). What could be wrong?</p>
  
  <p><strong>Update 1:</strong> When I use <code>Log.v("MyLog", config.locale.toString());</code> immediately after <code>res.updateConfiguration(config, dm)</code> it returns correct locale, but language of the app does not changed.</p>
  
  <p><strong>Update 2:</strong> I also mentioned that if I change locale and then restart the activity (using new intent and finish on the old one), it changes the language properly, it even shows correct language after rotation. But when I close the app and open it again, I get default language. It's weird.</p>
  
  <pre><code>public class ActivityMain extends AppCompatActivity {
  
      //...
      @Override
      protected void onCreate(Bundle savedInstanceState) { 
          super.onCreate(savedInstanceState);
          // Set locale
          SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
          String lang = pref.getString(ActivityMain.LANGUAGE_SAVED, "no_language");
          if (!lang.equals("no_language")) {
              Resources res = context.getResources();
              Locale locale = new Locale(lang);
              Locale.setDefault(locale);
              DisplayMetrics dm = res.getDisplayMetrics();
              Configuration config = res.getConfiguration();
              if (Build.VERSION.SDK_INT &gt;= 17) {
                  config.setLocale(locale);
              } else {
                  config.locale = locale;
              }
          }
          res.updateConfiguration(config, dm);
  
          setContentView(R.layout.activity_main);
          //...
      } 
      //... 
  }
  </code></pre>
  
  <p><strong>Update 3:</strong> <strong>THE ANSWER IS ALSO HERE:</strong> <a href="https://stackoverflow.com/a/40849142/3935063">https://stackoverflow.com/a/40849142/3935063</a></p>