重新启动单个任务活动

时间:2016-08-14 10:21:01

标签: android android-activity

我有一个singleTask活动而且我的app支持RT1,所以当我尝试更改语言时,这个SingleTask活动不受影响所以我需要重新启动它,任何帮助?

2 个答案:

答案 0 :(得分:3)

如果您使用的是API 11及更高版本,则可以使用:

Activity.recreate()

如果您需要支持较低的API,请使用此功能再次调用您的活动:

Intent i = getIntent();
finish();
startActivity(i);

答案 1 :(得分:0)

如果我们使用这种方法,我们不需要重新启动活动

使用以下代码更改您的应用语言:

public static void notifyForLanguageChange(Context context, String languageCode) {
        Resources res = context.getResources();
        // Change locale settings in the app.
        DisplayMetrics dm = res.getDisplayMetrics();
        android.content.res.Configuration conf = res.getConfiguration();
        conf.locale = new Locale(languageCode.toLowerCase());
        res.updateConfiguration(conf, dm);
    }

然后更改你的屏幕标签(即重新加载字符串资源)

public void setLabels() {
        txtFirstView.setText(R.string.first);
        txtSecondView.setText(R.string.second);
        btnThirdView.setText(R.string.third);
    }