Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebViewClient - onPageStarted() vs shouldOverrideUrlLoading()?

Tags:

android

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

like image 721
user291701 Avatar asked Mar 21 '12 16:03

user291701


People also ask

What is shouldOverrideUrlLoading?

shouldOverrideUrlLoading is called when a new page is about to be opened whereas shouldInterceptRequest is called each time a resource is loaded like a css file, a js file etc.

What is the use of Webviewclient in Android?

If you want to deliver a web application (or just a web page) as a part of a client application, you can do it using WebView . The WebView class is an extension of Android's View class that allows you to display web pages as a part of your activity layout.

What is Webviewclient?

Android WebView is a system component for the Android operating system (OS) that allows Android apps to display content from the web directly inside an application.


1 Answers

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.

like image 195
layman Avatar answered Oct 13 '22 00:10

layman