Issue
I have an activity containing a WebView:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
webView = new WebView(this);
setContentView(webView);
webView.getSettings().setUserAgentString(MY_CLIENT);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setWebViewClient(new MyWebViewClient());
}
My activity defines 2 menu items, which shall result in loading of 2 different URLs URL1 and URL2:
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_url1:
webView.loadUrl(URL1);
return true;
case R.id.menu_url2:
webView.loadUrl(URL2);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
However, an URL is only loaded for the 2nd time the according menu item is selected. Setting breakpoints in MyWebViewClient.onPageStarted() and MyWebViewClient.onPageFinished() shows that on the first click, onPageFinished() is called, but the url is not loaded into the WebView. On the 2nd click, onPageStarted() is invoked, followed by two invocations of onPageFinished(), and the url is loaded into the WebView. If I then try to load the other URL, the process starts over, and again two clicks are needed.
My target Android SDK is 17, min SDK is 8. I'm testing on a Nexus 7.
What do I have to do do make the WebView load an URL for the first click? And how can I debug such issues?
Solution
It looks like the problem is related to the URLs I'm trying to load - other URLs work just fine. Since for the ones I'm trying to load, I always have to perform two calls of loadURL(), I'm now just doing exactly that in the code - weird workaround, but works so far. I have to look into the URLs, thought...
Answered By - csoltenborn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.