title: Android runtime language changes not working when language is not present in the Add a language section
body: <p>I am attempting to change my app language locally using the following code. If English and French are present in the <strong>Add a language</strong> of my phone's Settings, and then go into my app and change the language, the language change is successful, but if I remove the language from the <strong>Add a language</strong> in the phone's settings, the changes doesn't work. From the examples I am seeing online, it should be possible to change it without having any additional languages in the <strong>Add a language</strong> of the phone's Settings. I'm not sure what I am doing wrong, is there a way to enable language changes without having to add the language in the phone settings?</p>
  <p>Any links to some documentation would also be quite appreciated.</p>
  <p>This is the LocalUtil object I am creating to enable the language switching:</p>
  <pre><code>object LocalUtil {
  
      fun applyLanguageContext(context: Context, locale: Locale?): Context {
  
          if (locale == null) return context
          if (locale == getLocale(context.resources.configuration)) return context
          return try {
              setupLocale(locale)
              val resources = context.resources
              val configuration = getOverridingConfig(locale, resources)
              updateResources(context, resources, configuration)
              context.createConfigurationContext(configuration)
          } catch (e: Exception) {
              e.printStackTrace()
              context
          }
      }
  
      private fun updateResources(
          context: Context,
          resources: Resources,
          config: Configuration
      ) {
          if (context.applicationContext !== context) {
              resources.updateConfiguration(config, resources.displayMetrics)
          }
      }
  
      private fun setupLocale(locale: Locale) {
          Locale.setDefault(locale)
          LocaleList.setDefault(LocaleList(locale))
      }
  
      private fun getOverridingConfig(locale: Locale, resources: Resources): Configuration {
          val configuration = resources.configuration
          configuration.setLocales(LocaleList(locale))
          return configuration
      }
  
      private fun getLocale(configuration: Configuration): Locale {
          return configuration.locales.get(0)
      }
  }
  </code></pre>
  <p>This is the Application() class which includes the LANGUAGE companion object variable</p>
  <pre><code>class MyApp: Application() {
  
      override fun getApplicationContext(): Context {
          val context = super.getApplicationContext()
          return LocalUtil.applyLanguageContext(context, Locale(LANGUAGE))
      }
  
      override fun attachBaseContext(newBase: Context) {
          super.attachBaseContext(LocalUtil.applyLanguageContext(newBase, Locale(LANGUAGE)))
      }
  
      companion object {
          var LANGUAGE = &quot;en&quot;
      }
  }
  </code></pre>
  <p>This is the <code>MainActivity.kt</code>, with a button that toggles between English &quot;en&quot; and French &quot;fr&quot; via the <code>changeLangBtn: Button</code></p>
  <pre><code>class MainActivity : AppCompatActivity() {
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
      }
  
      fun setChangeLangBtn(view: View) {
          val changeLangBtn: Button = findViewById(R.id.change_lang_btn)
          changeLangBtn.setOnClickListener {
              if (MyApp.LANGUAGE == &quot;en&quot;) MyApp.LANGUAGE = &quot;fr&quot; else MyApp.LANGUAGE = &quot;en&quot;
              reloadActivity()
          }
      }
  
      fun reloadActivity() {
           val intent = Intent(this, javaClass).apply {
               addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
               addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
           }
  
           startActivity(intent)
           recreate()
      }
  
      override fun getBaseContext(): Context {
          return LocalUtil.applyLanguageContext(super.getBaseContext(), Locale(MyApp.LANGUAGE))
      }
  
      override fun getApplicationContext(): Context {
          val context = super.getApplicationContext()
          return LocalUtil.applyLanguageContext(context, Locale(MyApp.LANGUAGE))
      }
  
      override fun attachBaseContext(newBase: Context) {
          super.attachBaseContext(LocalUtil.applyLanguageContext(newBase, Locale(MyApp.LANGUAGE)))
      }
  }
  </code></pre>