I have a over flow menu from where language is clicked to get singlechoiceitems(list of languages). I have written this code
AlertDialog.Builder languageDialog = new AlertDialog.Builder(
MainActivity.this);
languageDialog.setTitle(R.string.chooseLanguage);
final String[] languageOptions = { "English", "Nepali" };
languageDialog.setSingleChoiceItems(languageOptions, 0,
new DialogInterface.OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
setLanguage("es");
} else if (which == 1) {
setLanguage("ne");
}
dialog.dismiss();
}
});
languageDialog.show();
for list of Dailog and
@SuppressLint("NewApi")
private void setLanguage(String language) {
Locale locale = new Locale(language);
Locale.setDefault(locale);
android.content.res.Configuration config = new Configuration();
config.locale = locale;
this.getResources().updateConfiguration(config,
this.getResources().getDisplayMetrics());
MainActivity.this.recreate();
} method to set locale
The problem is that on screen orientation change the language changes back to device language, why?anything I am missing? I have made changes in anroid manifest file as I read but no solutions worked for me. Any help?