when my app get crashed for any reason or force close i hit OK button
on the message says "unfortunately the app has been stopped
" . then my app is come back again to same activity
, but it get it in other Language set and call OnResume()
my Question is how to make my app return to same Language config
even when my app has been crashed for some reason.
I'm trying to refresh and get the last config was set in sharedPreferences
and refresh my config or content view but no luck
Code :
@Override
public void onResume(){
super.onResume();
if(appSharedPrefs.getBoolean("IsArabic",true)){
Log.d("ERRRRR", "AR"); // that is called
setLocale(getApplicationContext(), "ar");
}
else{
Log.d("ERRRRR", "EN");
setLocale(getApplicationContext(), "en");
}
}
protected void setLocale(final Context ctx, final String lang)
{
Log.d("ERRRRR", lang);
/* final Locale loc = new Locale(lang);
Locale.setDefault(loc);
final Configuration cfg = new Configuration();
cfg.setLocale(loc);
ctx.getResources().updateConfiguration(cfg, null);*/
Resources res = ctx.getResources();
// Change locale settings in the app.
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
conf.locale = new Locale(lang.toLowerCase());
res.updateConfiguration(conf, dm);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
Log.d("ERRRRR", "onConfigurationChanged");
super.onConfigurationChanged(newConfig);
}