android: `recreate()` 不仅如此,还有最后一个 activity

android: `recreate()` not only this, but the last activity also

我使用此代码以编程方式更改我的应用程序的区域设置:

Locale.setDefault(locale);
Configuration config = getBaseContext().getResources().getConfiguration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
       getBaseContext().getResources().getDisplayMetrics());
recreate();

对于此 activity 和之后的所有活动都非常有效,但如果我使用手机的后退功能,最后的 activity 将重新使用,使用旧的语言环境。

有什么方法可以使最后一个 activity 无效或强制重新创建它?

这个post解决了问题:

我最终的解决方案是:

@Override
public void onResume() {
    super.onResume();
    if(!currentLanguage.equals(getResources().getConfiguration().locale.getLanguage())) {
        recreate();
    }
}

并在 onCreate() 中:

currentLanguage = getResources().getConfiguration().locale.getLanguage();

(应该搜索更多)。