6
votes

I'm using WebViewClient. Should we be seeing onPageStarted() callbacks always paired with an shouldOverrideUrlLoading() callback? If I load example.com in my WebView, should we be seeing both methods get called back? From the docs:

onPageStarted()

Notify the host application that a page has started loading. This method is called once for each main frame load so a page with iframes or framesets will call onPageStarted one time for the main frame. This also means that onPageStarted will not be called when the contents of an embedded frame changes, i.e. clicking a link whose target is an iframe.

shouldOverrideUrlLoading()

Give the host application a chance to take over the control when a new url is about to be loaded in the current WebView. If WebViewClient is not provided, by default WebView will ask Activity Manager to choose the proper handler for the url. If WebViewClient is provided, return true means the host application handles the url, while return false means the current WebView handles the url.

I'm put a log statement in each method, and I see that they're not always paired together. In what cases would they not be?

Thanks

http://developer.android.com/reference/android/webkit/WebViewClient.html

1
If you return true on shouldOverrideUrlLoading() then onPageStarted() will not get called. Beyond that, it might be possible that onPageStart will sometimes not get called if there are two requests back to back, thus potentially preventing one of them from going through. I'm not so confident about the latter, though.Reed
According to logs that I got in my application, shouldOverrideUrlLoading and onPageStarted can be called in any order, which is very confusing. I didn't yet find out at which circumstances this happens.Stan

1 Answers

1
votes

I know this question is old, but answering anyway. AFAIK, the shouldOverrideUrlLoading() will be called for every url in the page where as onPageStart() will be called only for the top url of the page.