首页 > 解决方案 > 重新创建();设置 AppCompatDelegate 后导致 ClassCast 异常

问题描述

如果我的介绍活动中的默认模式是暗模式,我正在尝试设置亮模式

介绍.java

if(AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_NO)
{
    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
    this.recreate();
}

但这会引发错误:

2020-10-25 07:04:43.626 9167-9167/com.xxxx.xxxxxx E/ActivityInjector: get life cycle exception
    java.lang.ClassCastException: android.os.BinderProxy cannot be cast to android.app.servertransaction.ClientTransaction

我在用

Theme.AppCompat.DayNight.NoActionBar

此外,主题不会在活动中更新。如果有人知道,请帮助我解决这个问题。

标签: android-studioandroid-appcompatclasscastexceptionandroid-night-mode

解决方案


推荐阅读