简体   繁体   English

Android-具有多个webViewClient的多个webView:在新的webViewClient上未调用shouldOverrideUrlLoading

[英]Android - multiple webViews with multiple webViewClient : shouldOverrideUrlLoading not called on new webViewClient

I have an android activity with a fragment dedicated for multiple webviews. 我有一个Android活动,其中一个片段专用于多个Webview。

I've implemented what i could about multiple webview methods including 我已经实现了关于多种Webview方法的能力,包括

public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) { 
    // source code here ... 
}

For the first webview, shouldOverrideUrlLoading(..) gets called OK. 对于第一个Web视图,应该将shouldOverrideUrlLoading(..)称为OK。

But as I follow some links and create a new webview, setup excatly the same as the first one, assign new webViewClient and new webChromeClient. 但是,当我点击一些链接并创建一个新的webview时,设置与第一个完全相同,分配新的webViewClient和新的webChromeClient。

The new webViewClient override functions such as onPageStart(..), onPageFinished(..) will call ok, 新的webViewClient覆盖函数(例如onPageStart(..),onPageFinished(..))将调用ok,

but only shouldOverrideUrlLoading() does not get called on the new webview despite it has a totally new webViewClient instance. 但是,尽管它具有全新的webViewClient实例,但只有在新的webview上不应该调用OverrideUrlLoading()。

I've checked the instance ids of both webViewClient and confirmed that they have different instance ids for each webviews (which is good because it means both webviews have actually different instances of webViewClients) 我已经检查了两个webViewClient的实例ID,并确认它们对于每个WebView都有不同的实例ID(这很好,因为这意味着两个WebView实际上具有不同的webViewClients实例)

I have no clue why the new instance of webViewClient will not trigger shouldOverrideUrlLoading() function. 我不知道为什么新的webViewClient实例不会触发shouldOverrideUrlLoading()函数。

Can anybody help me? 有谁能够帮助我? :( :(

Thanks! 谢谢!

Had a similiar situation. 情况类似。 In your web-client, you can implement the following: 在您的Web客户端中,您可以实现以下功能:

    @Override
    public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
       WebResourceResponse response = super.shouldInterceptRequest(view, request);
    return response;
}

and you can set a breakpoint in the middle to see what's going on. 您可以在中间设置一个断点以查看发生了什么。 My problem was that the request method was POST , and that did not trigger the shouldOverrideUrlLoading , so make sure that your request method is GET. 我的问题是请求方法是POST ,并且没有触发shouldOverrideUrlLoading ,因此请确保您的请求方法是GET。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM