I am saving user selected language in sharedpreference. when i close the app and restart it i read the value in sharedpreference by getValue method, and try to change the language. But my activity is stuck in loop.
I check this in onCreate
String language = getValue(getBaseContext()); if (language!= null && !language.isEmpty()) { changelanguage(language); } changeLanguage is as:
private void changelanguage(String languageToLoad) { Locale myLocale = new Locale(languageToLoad); Resources res = getResources(); DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.locale = myLocale; res.updateConfiguration(conf, dm); Intent refresh = new Intent(this, MainActivity.class); startActivity(refresh); finish(); save(this, languageToLoad); } How can i read and load user saved language on startup?
save()method simply does aSharedPreferences.Editor.commit())