该应用程序应该首先以默认语言启动吗?

should the app first start with the default language?

我已经为应用程序创建了 4 种语言。我可以更改Lauaguage,好的,但是如果关闭应用程序然后再次启动它,应用程序首先以默认值string.xml.

启动

如何让应用以上次选择的语言启动?

我应该在 mainActivity 中调用 OnCreate 方法吗?

     @SuppressWarnings("deprecation")
    public void setLocale(String lang) {
        Locale myLocale = new Locale(lang);

        DisplayMetrics dm = getResources().getDisplayMetrics();
        Configuration conf = getResources().getConfiguration();
        conf.locale = myLocale;
        getResources().updateConfiguration(conf, dm);
        Intent refresh = new Intent(this, Languages.class);
        startActivity(refresh);
        /*         "en" = English
            "hi" =Hindi
            "fr" =French
            "it" =Italian
            "de" =German
            "es" =Spanish
            "ja" =Japanese
            "ko" =Korean
            "nl" =Dutch
            "pt" =Portuguese
            "ru" =Russian
            "zh" =Chinese
            "ar" = arabic
   */
    }

用户如何更改默认语言?

为什么不将所选语言存储在共享首选项中?这样,您始终可以在应用程序启动时检查所选语言,然后加载适当的语言文件。

我已经使用了很长的方法,如下所示,但它有效。谢谢 :

恢复时:

    selected_lang= myshared.getString("selected_lang","de"); 
    lang_found= Integer.parseInt(myshared.getString("lang_found","0"));  
setLocale(selected_lang);



@SuppressWarnings("deprecation")
public void setLocale(String lang) {
    Locale myLocale = new Locale(lang);    
    DisplayMetrics dm = getResources().getDisplayMetrics();
    Configuration conf = getResources().getConfiguration();
    conf.locale = myLocale;
    getResources().updateConfiguration(conf, dm);

    if(lang_found==0) {    
        Intent refresh = new Intent(this, MainActivity.class);
        startActivity(refresh);
        lang_found=1;    
    }

@Override
protected void onDestroy() {

    lang_found=0;
    Save_setting();
    super.onDestroy();
}