Closed JulyStar-Lv closed 3 years ago
使用这个依赖试下有没有解决问题:
api 'com.github.vitaviva.fragivity:core:0af27f2e86'
发现是系统修改字体以后System.identityHashCode方法返回的hash不一样导致的;
还有一个问题,在include_common_title.xml
里可能需要把android:id="@+id/action_bar"
的id替换了,否则会出现异常:
2021-08-06 11:23:23.220 23282-23282/cn.net.cloudthink.smartmirror E/AndroidRuntime: FATAL EXCEPTION: main
Process: cn.net.cloudthink.smartmirror, PID: 23282
java.lang.RuntimeException: Unable to resume activity {cn.net.cloudthink.smartmirror/cn.net.cloudthink.smartmirror.app.HasLauncherActivity}: java.lang.IllegalStateException: Can't make a decor toolbar out of ConstraintLayout
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4910)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4953)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:190)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:105)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2462)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:219)
at android.app.ActivityThread.main(ActivityThread.java:8393)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
Caused by: java.lang.IllegalStateException: Can't make a decor toolbar out of ConstraintLayout
at androidx.appcompat.app.WindowDecorActionBar.getDecorToolbar(WindowDecorActionBar.java:241)
at androidx.appcompat.app.WindowDecorActionBar.init(WindowDecorActionBar.java:197)
at androidx.appcompat.app.WindowDecorActionBar.<init>(WindowDecorActionBar.java:173)
at androidx.appcompat.app.AppCompatDelegateImpl.initWindowDecorActionBar(AppCompatDelegateImpl.java:554)
at androidx.appcompat.app.AppCompatDelegateImpl.getSupportActionBar(AppCompatDelegateImpl.java:534)
at androidx.appcompat.app.AppCompatDelegateImpl.onPostResume(AppCompatDelegateImpl.java:676)
at androidx.appcompat.app.AppCompatActivity.onPostResume(AppCompatActivity.java:205)
at android.app.Activity.performResume(Activity.java:8283)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4900)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4953)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:190)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:105)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2462)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:219)
at android.app.ActivityThread.main(ActivityThread.java:8393)
修改字体大小不闪退了,但修改显示大小的话,还是一样的闪退。
原因大同小异,修改显示大小以后hashCode
会不一样;
// 默认
KClass hashCode=134872401,Class hashCode=134872401, identityHashCode=85309878
// 修改系统字体
KClass hashCode=134872401,Class hashCode=134872401, identityHashCode=98088601
// 修改显示大小
KClass hashCode=219334063,Class hashCode=219334063, identityHashCode=227782076
知识盲区了,被这玩意整破防了,我去找大师们帮忙了。
试试这个,应该可以了:
api 'com.github.vitaviva.fragivity:core:0c23fb4f21'
已解决,谢谢!!!
原因大同小异,修改显示大小以后
hashCode
会不一样;// 默认 KClass hashCode=134872401,Class hashCode=134872401, identityHashCode=85309878 // 修改系统字体 KClass hashCode=134872401,Class hashCode=134872401, identityHashCode=98088601 // 修改显示大小 KClass hashCode=219334063,Class hashCode=219334063, identityHashCode=227782076
知识盲区了,被这玩意整破防了,我去找大师们帮忙了。
记录下: 修改字体大小后应该是刷新了Activity,而System.identityHashCode()在计算包含了系统字体大小导致结果不同; 修改显示大小后应该是重启了app,导致class不同。
你好,又来打扰了! 打开App后,放在后台,进设置调整显示大小后,再切回App,发生闪退, 我的demo会有这个问题, 链接 demo下载地址
还是上次那个demo,麻烦看下,谢谢!