【问题标题】:Activity OnConfigurationChange is not being called未调用 Activity OnConfigurationChange
【发布时间】:2015-11-22 22:30:11
【问题描述】:

我的活动 onConfigurationChanged 根本没有被调用。我已将我的 SDK API 更新为 Marshmallow ;

在我的代码中覆盖“onConfigurationChanged”:

@Override
    public void onConfigurationChanged(Configuration newConfig) {
    Log.d(HomeActivity.class.getSimpleName() , "called"); // not called
    super.onConfigurationChanged(newConfig);
    Log.d(HomeActivity.class.getSimpleName(), "called"); // not called

在我的 Android 清单中我声明:

<activity
            android:name=".activities.HomeActivity"
            android:configChanges="layoutDirection|locale"

我呼吁改变语言:

public void changeLocale(Locale locale) {
        Resources res = mContext.getResources();
        DisplayMetrics dm = res.getDisplayMetrics();
        android.content.res.Configuration conf = res.getConfiguration();
        conf.locale = new Locale(locale.toString().toLowerCase());
        res.updateConfiguration(conf, dm);
}

有谁知道发生了什么变化或我做错了什么/错过了什么?

谢谢

【问题讨论】:

    标签: android android-activity onconfigurationchanged


    【解决方案1】:

    onConfigurationChanged() 只有在用户更改手机的区域设置(语言)时才会被调用。只是调用Resources.updateConfiguration() 不会触发这个。

    【讨论】:

      【解决方案2】:

      请删除android:configChanges="layoutDirection|locale"

      【讨论】:

        【解决方案3】:

        尝试将此添加到您的活动下的清单中

        android:configChanges="keyboardHidden|orientation|screenSize"
        

        【讨论】:

        • 如果回答了您的问题,请将其标记为正确
        猜你喜欢
        • 1970-01-01
        • 2013-09-14
        • 2017-03-06
        • 2015-07-04
        • 2023-04-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多