3

Just recently, context.getResources().updateConfiguration() has been deprecated in Android API 25 and I need to change language of my app which user selects. I am using this method to change language

  private void setLanguage(String language){
    Locale locale = new Locale(language);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    con.getApplicationContext().getResources().updateConfiguration(config, null);
    prefData.setCurrentLanguage(language);
    Intent intent = new Intent(getApplicationContext(),MainActivity.class);
    startActivity(intent);
    finish();

}

But getting Deprecated api warning, I have just started android development. So any suggestion will be helpful on how to resolve this warning.

Zoe
  • 27,060
  • 21
  • 118
  • 148
  • Try [this](https://stackoverflow.com/questions/40221711/android-context-getresources-updateconfiguration-deprecated) – Davi Feb 19 '19 at 21:36

1 Answers1

4

I found below code in the Resource source code.

 /**
     * Store the newly updated configuration.
     *
     * @deprecated See {@link android.content.Context#createConfigurationContext(Configuration)}.
     */
    @Deprecated
    public void updateConfiguration(Configuration config, DisplayMetrics metrics) {
        updateConfiguration(config, metrics, null);
    }

The doc says it has been deprecated that you should use Context.createConfigurationContext(Configuration) instead.

devmike01
  • 1,971
  • 1
  • 20
  • 30