When the page with the WebView first loads, sometimes images are missing or displayed incorrectly. If I reload the page the WebView always displays perfectly. I know everyone will first think I set javascript after loadUrl, but that isn't true.
In onCreate I have:
learnWebView = (WebView)findViewById(R.id.learnWebView);
learnWebView.setWebViewClient(new WebViewClient());
learnWebView.getSettings().setJavaScriptEnabled(true);
Then later in the function called after onCreate I have:
learnWebView.loadUrl("myurl");
And yes, I know that the function with loadUrl is called after onCreate every time.
Please try this instead of your way, that is a bad practice:
learnWebView.post(new Runnable() {
@Override
public void run() {
learnWebView.loadUrl("myurl");
}
});
Or this, in case the first one wont work:
learnWebView.postDelayed(new Runnable() {
@Override
public void run() {
learnWebView.loadUrl("myurl");
}
}, 500);
Hope this helps.
Look at onViewAttachedToWindow
.
You should process your logic in javascript only after onViewAttachedToWindow
fired.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With