vitaviva / fragivity

Use Fragment like Activity
https://juejin.cn/post/6918693610359619592
MIT License
298 stars 40 forks source link

调整显示大小,发生闪退 #48

Closed JulyStar-Lv closed 3 years ago

JulyStar-Lv commented 3 years ago

你好,又来打扰了! 打开App后,放在后台,进设置调整显示大小后,再切回App,发生闪退, 我的demo会有这个问题, 链接 demo下载地址

还是上次那个demo,麻烦看下,谢谢!

08-05 21:56:13.014 22162 22162 E AndroidRuntime: FATAL EXCEPTION: main
08-05 21:56:13.014 22162 22162 E AndroidRuntime: Process: cn.net.cloudthink.smartmirror, PID: 22162
08-05 21:56:13.014 22162 22162 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{cn.net.cloudthink.smartmirror/cn.net.cloudthink.smartmirror.app.HasLauncherActivity}: java.lang.IllegalStateException: Restoring the Navigation back stack failed: destination 232410147 cannot be found from the current destination NavGraph(0x0) startDestination={Destination(0x31b934c) label=cn.net.cloudthink.smartmirror.app.fragment.MainFragment class=cn.net.cloudthink.smartmirror.app.fragment.MainFragment}
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3540)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3700)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:106)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:236)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:8061)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
08-05 21:56:13.014 22162 22162 E AndroidRuntime: Caused by: java.lang.IllegalStateException: Restoring the Navigation back stack failed: destination 232410147 cannot be found from the current destination NavGraph(0x0) startDestination={Destination(0x31b934c) label=cn.net.cloudthink.smartmirror.app.fragment.MainFragment class=cn.net.cloudthink.smartmirror.app.fragment.MainFragment}
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at androidx.navigation.NavController.onGraphCreated(NavController.java:619)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at androidx.navigation.NavController.setGraph(NavController.java:592)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at androidx.navigation.NavController.setGraph(NavController.java:572)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at com.github.fragivity.FragivityUtil__ActionLoadRootKt.loadRootInternal$FragivityUtil__ActionLoadRootKt(ActionLoadRoot.kt:89)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at com.github.fragivity.FragivityUtil__ActionLoadRootKt.loadRoot(ActionLoadRoot.kt:53)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at com.github.fragivity.FragivityUtil.loadRoot(Unknown Source:1)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at com.github.fragivity.FragivityUtil__ActionLoadRootKt.loadRoot(ActionLoadRoot.kt:48)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at com.github.fragivity.FragivityUtil.loadRoot(Unknown Source:1)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at cn.net.cloudthink.smartmirror.app.HasLauncherActivity.initView(HasLauncherActivity.kt:34)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at cn.com.broadlink.library.base.app.activity.BaseVmActivity.init(BaseVmActivity.kt:45)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at cn.com.broadlink.library.base.app.activity.BaseVmActivity.onCreate(BaseVmActivity.kt:39)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at cn.com.broadlink.library.base.app.activity.BaseVmDbActivity.onCreate(BaseVmDbActivity.kt:20)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at cn.net.cloudthink.smartmirror.app.HasLauncherActivity.onCreate(HasLauncherActivity.kt:25)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.app.Activity.performCreate(Activity.java:8127)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.app.Activity.performCreate(Activity.java:8098)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1310)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3513)
08-05 21:56:13.014 22162 22162 E AndroidRuntime:        ... 11 more
qdsfdhvh commented 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)
JulyStar-Lv commented 3 years ago

修改字体大小不闪退了,但修改显示大小的话,还是一样的闪退。

qdsfdhvh commented 3 years ago

原因大同小异,修改显示大小以后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

知识盲区了,被这玩意整破防了,我去找大师们帮忙了。

qdsfdhvh commented 3 years ago

试试这个,应该可以了:

api 'com.github.vitaviva.fragivity:core:0c23fb4f21'
JulyStar-Lv commented 3 years ago

已解决,谢谢!!!

qdsfdhvh commented 3 years ago

原因大同小异,修改显示大小以后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不同。