Android WebViewClient回调调用过于频繁

Android WebViewClient回调调用过于频繁,第1张

概述当我调用WebView#loadUrl时,我希望我只能获得一个WebViewClient#onPageFinished调用而没有WebViewClient#shouldOverrideUrlLoading调用.但是,我得到了一个WebViewClient#shouldOverrideUrlLoading(我通过始终调用WebView#loadUrl并返回true来实现),然后是两个具有相同URL的WebView

当我调用WebVIEw#loadUrl时,我希望我只能获得一个WebVIEwClIEnt#onPageFinished调用而没有WebVIEwClIEnt#shouldOverrIDeUrlLoading调用.但是,我得到了一个WebVIEwClIEnt#shouldOverrIDeUrlLoading(我通过始终调用WebVIEw#loadUrl并返回true来实现),然后是两个具有相同URL的WebVIEwClIEnt#onPageFinished调用.

我正在加载的页面使用了很多AJAX请求. AJAX请求是否会调用WebVIEwClIEnt?我的页面中没有任何Meta-refreshes.

这非常令人沮丧.难道我做错了什么?

解决方法:

这是a google groups discussion I started on the topic的交叉帖子.

我做了更多的研究,我想我理解正在发生的一切.

这是我的WebVIEwClIEnt:

public class MyWebVIEwClIEnt extends WebVIEwClIEnt {  @OverrIDe  public voID onPageStarted(WebVIEw vIEw, String url, Bitmap favicon) {    System.out.println("onPageStarted: " + url);  }  @OverrIDe  public boolean shouldOverrIDeUrlLoading(WebVIEw webVIEw, String url) {    System.out.println("shouldOverrIDeUrlLoading: " + url);    webVIEw.loadUrl(url);    return true;  }  @OverrIDe  public voID onPageFinished(WebVIEw webVIEw, String url) {    System.out.println("onPageFinished: " + url);  }}

我的服务器有以下URL重定向:

http://example.com/resource -> http://example.com/user-name/resourcehttp://example.com/logout.Jsp -> http://example.com/login/logouthttp://example.com/login/logout -> http://example.com/login

这些URL是我无法控制的服务器的一部分,因此我只需处理该行为.

以下是加载http://example.com/resource的输出

onPageStarted: http://example.com/resourceonPageStarted: http://example.com/user-name/resourceshouldOverrIDeUrlLoading: http://example.com/user-name/resourceonPageFinished: hhttp://example.com/user-name/resource

此时,我的WebVIEw有空白内容.我必须等到第二次onPageFinished后才能抓住我的内容.

onPageStarted: http://example.coms/user-name/resourceonPageFinished: http://example.com/user-name/resource

以下是加载http://example.com/logout.Jsp的输出

onPageStarted: http://example.com/logout.JsponPageStarted: http://example.com/login/logoutshouldOverrIDeUrlLoading: http://example.com/login/logoutonPageFinished: http://example.com/login/logoutonPageStarted: http://example.com/login/logoutonPageStarted: http://example.com/loginshouldOverrIDeUrlLoading: http://example.com/loginonPageFinished: http://example.com/login

再次,此时,我的WebVIEw有一个空白页面.我必须等到第3次onPageFinished才能从WebVIEw获取我的内容.

onPageStarted: http://example.com/loginonPageFinished: http://example.com/login

根据文档,我不指望这种行为.请注意,onPageStarteds和onPageFinisheds的数量不平衡.我特别不喜欢用重定向的URL调用onPageFinished,但WebVIEw不包含我的内容.我知道这种行为可能是不可改变的,但至少应记录这种意外行为.

总结

以上是内存溢出为你收集整理的Android WebViewClient回调调用过于频繁全部内容,希望文章能够帮你解决Android WebViewClient回调调用过于频繁所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1120093.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存