这是我在该主题上开始的谷歌群组讨论的交叉帖子。
我做了更多的研究,我想我了解正在发生的一切。
这是我的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/resource
http://example.com/logout.jsp -> http://example.com/login/logout
http://example.com/login/logout -> http://example.com/login
这些 URL 是我无法控制的服务器的一部分,所以我只需要处理这些行为。
这是加载的输出http://example.com/resource
onPageStarted: http://example.com/resource
onPageStarted: http://example.com/user-name/resource
shouldOverrideUrlLoading: http://example.com/user-name/resource
onPageFinished: hhttp://example.com/user-name/resource
此时,我WebView
的内容为空白。我必须等到第二个之后onPageFinished
才能获取我的内容。
onPageStarted: http://example.coms/user-name/resource
onPageFinished: http://example.com/user-name/resource
这是加载的输出http://example.com/logout.jsp
onPageStarted: http://example.com/logout.jsp
onPageStarted: http://example.com/login/logout
shouldOverrideUrlLoading: http://example.com/login/logout
onPageFinished: http://example.com/login/logout
onPageStarted: http://example.com/login/logout
onPageStarted: http://example.com/login
shouldOverrideUrlLoading: http://example.com/login
onPageFinished: http://example.com/login
同样,此时,我WebView
有一个空白页。我必须等到 3 日onPageFinished
才能从WebView
.
onPageStarted: http://example.com/login
onPageFinished: http://example.com/login
根据文档,我不希望出现这种行为。onPageStarted
请注意, s 和s的数量不平衡onPageFinished
。我特别不喜欢如何onPageFinished
使用我的重定向 URL 进行调用,但WebView
它不包含我的内容。我知道这种行为可能是不可改变的,但至少应该记录这种意外行为。