【发布时间】:2021-02-10 08:45:03
【问题描述】:
自从 MIUI 11/12 使用它自己的暗模式自定义实现,使用下面的代码会导致 ClassCastException 和 Activity 生命周期异常,因为 DefaultNightMode 和 LocalNightMode 始终未指定,即 -100 而不是 0 或 1。
如果有人专门为 MIUI 11/12 构建了针对小米设备的解决方法。请帮帮我。
使用的代码:
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
【问题讨论】:
-
你看过这个吗? developer.android.com/guide/topics/ui/look-and-feel/darktheme 它说重新创建活动是不必要的。根据 MIUI 下的 Android 版本,这可能是问题所在。
-
感谢您的回复。我已经看过了,问题不在于Android,它是最重要的MIUI皮肤。该应用程序在 Stock Android(相同的 api)上运行良好。
-
我认为异常来自函数
Activity.recreate(),在小米设备上似乎给出了这个错误。
标签: android-studio classcastexception android-dark-theme miui darkmode