Saturday, 20 May 2017

Android webview launches browser when calling loadurl



I created an Activity that has a title and a web view in a LinearLayout. In the onResume() method it calls webView.loadUrl(url). The problem is that the activity first shows the title with the rest of the screen blank, then the device browser is launched with the page for the URL. What I want to see is the page being shown in the WebView below the title. What could be the problem?



Edit:
Ok, did some further search and found this one:




Clicking URLs opens default browser



It points to the WebView tutorial here.



Just implement the web client and set it.


Answer



Answering my question based on the suggestions from Maudicus and Hit.



Check the WebView tutorial here.
Just implement the web client and set it before loadUrl. The simplest way is:




myWebView.setWebViewClient(new WebViewClient());


For more advanced processing for the web content, consider the ChromeClient.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...