MIUI 11/12 Theme Switch Results in LifeCycleException, ClassCastException

Deadly 提交于 2020-12-26 16:32:45

问题


Since MIUI 11/12 Use Its Own Custom Implementation of Dark Mode, using below code results in ClassCastException and Activity Life Cycle Exception, as DefaultNightMode and LocalNightMode is always Unspecified i.e. -100 instead of 0 or 1.

If anyone has built a workaround for Xiaomi Devices specially for MIUI 11/12. Please Help Me Out On this.

Code Used:

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
this.recreate();

Error Caused:

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

回答1:


I solved it myself. After fiddling around with it for a week, I did it..

Here is how:

-- Instead of setting android:forceDarkAllowed="false" for each and every Activity.

-- Just goto values.xml and place this in your AppTheme

        <item name="android:forceDarkAllowed">false</item>

It will ask you to create a valuesv29.xml. Create it, and remove the forceDarkAllowed="false" from all activities.

Welcome. :)



来源:https://stackoverflow.com/questions/64565156/miui-11-12-theme-switch-results-in-lifecycleexception-classcastexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!