android - How to make language preference be applied immediately? -


i've managed create switch preference allowing me enable , disable language, cannot apply changes after option has been selected.

<preferencescreen         xmlns:android="http://schemas.android.com/apk/res/android">   <preferencecategory         android:title="language">     <switchpreference         android:title="@string/setting_enable"         android:key="checkbox_lang"         android:summaryon="@string/settings_sum_en"         android:summaryoff="@string/settings_sum_dis"         android:defaultvalue="false"/>  </preferencecategory>   </preferencescreen> 

the code below used change language settings.

private void loadpreferences(){     //allows preferances screen in application     sharedpreferences sharedpreferences = preferencemanager.getdefaultsharedpreferences(this);      boolean isengchecked = sharedpreferences.getboolean("checkbox_lang",false);     if (isengchecked){          string languagetoload  = "default"; //selected default language (english)         locale locale = new locale(languagetoload);         locale.setdefault(locale);         configuration config = new configuration();         config.locale = locale;         getbasecontext().getresources().updateconfiguration(config, getbasecontext().getresources().getdisplaymetrics());      } else {          string languagetoload  = "ar"; // language         locale locale = new locale(languagetoload);         locale.setdefault(locale);         configuration config = new configuration();         config.locale = locale;         getbasecontext().getresources().updateconfiguration(config, getbasecontext().getresources().getdisplaymetrics());      }  } 

how can change code allow change happen immediately?

p.s i've tried recreate activity creates more problems when application opened after closed (displays white screen).


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

c# - Json.Net Serialize String from URI -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -