我有一个带有WebView的片段,在其中我重写了一个特定的URL,以触发到另一个片段的导航。我无法重现它,但是我收到带有以下堆栈跟踪的崩溃报告:
Fatal Exception: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at androidx.fragment.app.FragmentManagerImpl.checkStateLoss(SourceFile:2080)
at androidx.fragment.app.FragmentManagerImpl.enqueueAction(SourceFile:2106)
at androidx.fragment.app.BackStackRecord.commitInternal(SourceFile:683)
at androidx.fragment.app.BackStackRecord.commit(SourceFile:637)
... (navigation library calls)
at app.Activity.navigate(SourceFile:70)
at app.WebFragment$onDone$1.invoke(SourceFile:25)
at app.WebViewClient.shouldOverrideUrlLoading(SourceFile:29)
at jU.b(PG:83)
at org.chromium.android_webview.AwContentsClientBridge.shouldOverrideUrlLoading(PG:172)
at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
at android.os.MessageQueue.next(MessageQueue.java:323)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
我认为这是因为app.Activity.navigate
在活动停止后被调用,这就是checkStateLoss()
返回true的原因。
如果活动被停止,WebView是否应该销毁并停止调用回调?
还是应该在片段的某个时刻(在WebView#onDestroy()
或其他生命周期事件中调用onStop
?