In my Android app i want to change the default language dinamically. I have implemented this method:
public void changeLanguage(String lang) { //lang="it" or "en" for example
myLocale = new Locale(lang);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
@Override
public void run()
{
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
{
finish();
startActivity(getIntent());
} else recreate();
}
}, 1);
}
and in the manifest i added to my MainActivity this line:
android:configChanges="locale|orientation"
i also tried this:
android:configChanges="locale|layoutDirection"
This solution works well, but as soon as the screen is rotated comes back to the default configuration and the language is restored.
How can i resolve this issue?