0

I have implemented change language from settings as per this ans , but after killing of my application some of the screen of application turned to english.

I have implemented code as below Code for Splash Screen

String   deviceLanguage = Locale.getDefault().getLanguage();

if (!"en".equalsIgnoreCase(deviceLanguage) && !"ar".equalsIgnoreCase(deviceLanguage)){
            deviceLanguage="en";
        }
((AppController)getApplication()).appLang= Utilities.getSaveData(this, getString(R.string.key_language),deviceLanguage);

Code for Detail Activity

@Override
protected void attachBaseContext(Context newBase) {
    super.attachBaseContext(MyContextWrapper.wrap(newBase, ((AppController)newBase.getApplicationContext()).appLang));
}

Note : I got this problem in one plus 3T device and genymotion emulator with 5.1 android version

Krutik
  • 732
  • 6
  • 19
  • The actual problem is customize os in some customize os in that they can select multiple languages same time and it creates issue – Krutik Aug 22 '17 at 09:50

1 Answers1

1
final Resources res = appContext.getResources();
final Configuration conf = res.getConfiguration();
conf.locale = new Locale("ar", "AE");      
res.updateConfiguration(conf, null);

After updating configuration, Restart the activity as mentioned below

finish();
final Intent intent = getIntent();
startActivity(intent);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
prakash
  • 162
  • 3
  • Something like this, but I would rather put the locale setting into `Application` already, and restart whole app after change, not only current Activity. I can't recall any details (since I last did something similar, and that's like 3-4 years back), but IIRC on some older versions of Android and on some devices, restarting only Activity may produce some unwanted artefacts, with some bits staying initialized with the original Locale. – Ped7g Aug 17 '17 at 11:36