Android- Webview onPageFinished Called Twice

后端 未结 7 981
名媛妹妹
名媛妹妹 2020-12-05 14:08

I have an activity that does OAuth authentication by intercepting the redirect url once it show up in the webview. However, the onPageFinished function is somehow called twi

相关标签:
7条回答
  • 2020-12-05 14:46

    I'm looking into an event where m.yotube.com triggers two onPageFinished events but it does not seem like caused by redirection to me. After some studies I found that there is one extra onPageFinished triggered by didFinishNavigation before the one triggered by didStopLoading which other pages also receives.

    stack trace #1 stack trace #2

    See also:

    https://chromium.googlesource.com/chromium/src.git/+/master/android_webview/java/src/org/chromium/android_webview/AwWebContentsObserver.java

        @Override
        public void didFinishNavigation(final String url, boolean isInMainFrame, boolean isErrorPage,
                boolean hasCommitted, boolean isSameDocument, boolean isFragmentNavigation,
                Integer pageTransition, int errorCode, String errorDescription, int httpStatusCode) {
            ...
            if (client != null && isFragmentNavigation) {
                client.getCallbackHelper().postOnPageFinished(url);
            }
        }
    
        @Override
        public void didStopLoading(String validatedUrl) {
            if (validatedUrl.length() == 0) validatedUrl = ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL;
                AwContentsClient client = getClientIfNeedToFireCallback(validatedUrl);
            if (client != null && validatedUrl.equals(mLastDidFinishLoadUrl)) {
                client.getCallbackHelper().postOnPageFinished(validatedUrl);
            mLastDidFinishLoadUrl = null;
            }
        }
    

    Another instance I receive extra onPageFinished calls (even before onPageStarted!) is when I utilize webview.restoreState() in Fragments. it fires two onPageFinished events when trying to resume last viewed page.

    0 讨论(0)
提交回复
热议问题