0

i am changes my app language to other language.. This code is in my main activity.

lang = from SharedPreferenes;

Configuration config = getBaseContext().getResources()
                .getConfiguration();

if (!config.locale.getLanguage().equals(lang)) {
Locale locale2 = new Locale(lang);
Locale.setDefault(locale2);
Configuration config2 = new Configuration();
config2.locale = locale2;
mContext.getResources().updateConfiguration(config2, null);
}

When i change orientation and click a button to open next activity, language change back to the default phone language(English). i Did try to use locale in manifest android:configChanges="keyboardHidden|orientation|locale" but no effect....any idea how to do it

ravi
  • 1
  • 1
    Put the code in the OnCreate method of each activity – Kuffs Nov 14 '13 at 11:51
  • when orientation changes your activity recreates [check this][1] [1]: http://stackoverflow.com/questions/456211/activity-restart-on-rotation-android – pavanmvn Nov 14 '13 at 11:54
  • The best way would be for the application to use the device's main language. http://developer.android.com/training/basics/supporting-devices/languages.html Otherwise @Kuffs suggestion will work, but i suggest to write a base activity with that code and extend your activities from the base activity – Alex Nov 14 '13 at 11:56
  • Why are you changing the locale with code? – Squonk Nov 14 '13 at 12:02
  • thanks guys... i do get a solution but it is little bit heavy on device. What i did was put that code in BroadcastReceiver and check of orientation change intent. So every time user device orientation change i check user's selected language and save it in local again... – ravi Nov 15 '13 at 05:07
  • http://stackoverflow.com/questions/456211/activity-restart-on-rotation-android – rajeesh Jan 02 '14 at 06:55

0 Answers0