Reputation: 1035
I have an app that I want to use in both english and hebrew. I've added two String files under values and values-iw folders. When a user is selecting a different language, I run this code:
Locale locale;
if (location.equals("iw")){
locale= new Locale("iw");
Errors._langauge=1;
}
else{
locale=Locale.ENGLISH;
Errors._langauge=2;
}
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
This is working fine until I lay my device, causing the xml in layout-land directory to be loaded. When the land xml is loaded the language goes back to default language of the system. How can I prevent that from happening?
Upvotes: 0
Views: 259
Reputation: 151
When changing the orientation, your Activity recreates itself, so your onCreate() gonna run again. I assume you are initializing the default value in your onCreate() method, so it changes itself back.
Upvotes: 2