0
後工作時,我的應用程序崩潰得到以任何理由或強制關閉我打的消息OK button
說:「unfortunately the app has been stopped
」。然後我的應用程序再次回到同一activity
,但它得到它在其他語言設定和調用OnResume()
改變編程語言不應用強制關閉
我的問題是如何讓我的應用程序迴歸到同一Language config
即使我的應用程序已經崩潰的某些原因。
我試圖刷新並獲得最後的配置在sharedPreferences
設置和刷新我的配置或內容的看法,但沒有運氣
代碼:
@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);
}
我的問題是不是在SharedPreferences使用它,它爲我工作,但得到的右侍郎之後,佈局仍然工作在其他的語言我的應用程序後墜毀 –
應用得到了墜毀後...共享偏好失去了它的價值讓你'appSharedPrefs.getBoolean'爲您提供了錯誤的值 – rafsanahmad007
看到這一點:http://stackoverflow.com/questions/15353900/shared -preferences-reset-data-when-app-is-force-closed-or-device-is-restarted – rafsanahmad007