Android webviewclient callback calls are too frequent
When I call WebView #loadurl, I hope I can only get one webviewclient #onpagefinished call without webviewclient #shouldoverrideurloading call. However, I get a webviewclient #shouldoverrideurloading (I implement it by always calling WebView #loadurl and returning true), and then two webviewclient #onpagefinished calls with the same URL
The page I am loading uses many Ajax requests. Will the Ajax request call webviewclient? There are no meta refreshes in my page
It's very frustrating. Did I do something wrong?
resolvent:
This is a cross post of a Google Groups discussion I started on the topic
I've done more research and I think I understand what's happening
This is my 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);
}
}
My server has the following URL redirects:
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
These URLs are part of a server that I can't control, so I just need to deal with this behavior
The following is the loading http://example.com/resource Output of
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
At this time, my WebView has blank content. I can't catch my content until onpagefinished the second time
onPageStarted: http://example.coms/user-name/resource
onPageFinished: http://example.com/user-name/resource
The following is the loading http://example.com/logout.jsp Output of
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
Again, at this time, my WebView has a blank page. I must wait until onpagefinished for the third time to get my content from WebView
onPageStarted: http://example.com/login
onPageFinished: http://example.com/login
According to the documentation, I don't expect this behavior. Please note that the number of onpagestarts and onpagefinishes is unbalanced. I especially don't like calling onpagefinished with redirected URL, but WebView doesn't contain my content. I know this behavior may not be changed, but at least this unexpected behavior should be recorded