Selected language not working on switching activities with different orientations.
farooqkhan003 opened this issue · comments
Farooq Khan commented
If we open new activity with different orientation and came back to the previous activity, it does not show the selected language.
Faisal Naseer commented
did you find any solution, I am facing the same issue?
vishwas89 commented
anybody found solution, I am also facing same issue
Faisal Naseer commented
Yes i tried by re-attaching the base context. You can try in particular
activity
@OverRide
protected void attachBaseContext(Context newBase) {
prefS = PreferenceManager.getDefaultSharedPreferences(newBase);
editor = prefS.edit();
mcaGlobal = (MyApp)newBase.getApplicationContext();
if(prefS.getBoolean("LangSet",false)){
if(!prefS.getString("Lang","").equals("")){
mcaGlobal.setLang(prefS.getString("Lang",""));
}
}
lang=mcaGlobal.getLang();
super.attachBaseContext(mContextWrapper.wrap(newBase,lang));
}
…On Wed, Oct 11, 2017 at 12:04 PM, vishwas89 ***@***.***> wrote:
anybody found solution, I am also facing same issue
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AO8Ul2KEmL7zgnQ0UsQyvrqD53_qytP3ks5srGhngaJpZM4Ox5U7>
.
Faisal Naseer commented
public class mContextWrapper extends ContextWrapper {
public mContextWrapper(Context base){
super(base);
}
@SuppressWarnings("deprecation")
public static ContextWrapper wrap(Context context, String language) {
Configuration config = context.getResources().getConfiguration();
Locale sysLocale = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
sysLocale = getSystemLocale(config);
} else {
sysLocale = getSystemLocaleLegacy(config);
}
if (!language.equals("") && !sysLocale.getLanguage().equals(language)) {
Locale locale = new Locale(language);
Locale.setDefault(locale);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
setSystemLocale(config, locale);
} else {
setSystemLocaleLegacy(config, locale);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
context = context.createConfigurationContext(config);
} else {
context.getResources().updateConfiguration(config,
context.getResources().getDisplayMetrics());
}
}
return new mContextWrapper(context);
}
@SuppressWarnings("deprecation")
public static Locale getSystemLocaleLegacy(Configuration config){
return config.locale;
}
@TargetApi(Build.VERSION_CODES.N)
public static Locale getSystemLocale(Configuration config){
return config.getLocales().get(0);
}
@SuppressWarnings("deprecation")
public static void setSystemLocaleLegacy(Configuration config,
Locale locale){
config.locale = locale;
}
@TargetApi(Build.VERSION_CODES.N)
public static void setSystemLocale(Configuration config, Locale locale){
config.setLocale(locale);
}
}
…On Wed, Oct 11, 2017 at 12:59 PM, faisal naseer ***@***.***> wrote:
Yes i tried by re-attaching the base context. You can try in particular
activity
@OverRide
protected void attachBaseContext(Context newBase) {
prefS = PreferenceManager.getDefaultSharedPreferences(newBase);
editor = prefS.edit();
mcaGlobal = (MyApp)newBase.getApplicationContext();
if(prefS.getBoolean("LangSet",false)){
if(!prefS.getString("Lang","").equals("")){
mcaGlobal.setLang(prefS.getString("Lang",""));
}
}
lang=mcaGlobal.getLang();
super.attachBaseContext(mContextWrapper.wrap(newBase,lang));
}
On Wed, Oct 11, 2017 at 12:04 PM, vishwas89 ***@***.***>
wrote:
> anybody found solution, I am also facing same issue
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <#14 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AO8Ul2KEmL7zgnQ0UsQyvrqD53_qytP3ks5srGhngaJpZM4Ox5U7>
> .
>
vishwas89 commented
thanks for the reply
Actually i have lot of fragments on Activity 1 and there is another Activity 2 which default orientation to landscape when i return to Activity 1 (which is in PORTRAIT mode containing fragment) all the fragment language get change can you send the full code please please help