I have a webview I am loading custom HTML into using loadDataWithBaseURL
:
mArticleWebView.loadDataWithBaseURL("http://www.example.com/", htmlString, "text/html", "utf-8", null);
This will work for several pages, and then events stop firing in the WebView for seemingly no reason in Jelly Bean on tablets and the web's view will be blank.
This this the WebViewCreation
Code:
private void prepareWebView() {
mArticleWebView.setBackgroundColor(getResources().getColor(R.color.white));
mArticleWebView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);
mArticleWebView.addJavascriptInterface(new ArticleJavaScriptInterface(getActivity()), "Company");
mArticleWebView.setWebChromeClient(new CustomChromeClient());
/* WebViewClient must be set BEFORE calling loadUrl! */
mArticleWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favi) {
Log.e(TAG, "Signs of life, shock and awe.");
super.onPageStarted(view, url, favi);
}
@Override
public void onPageFinished(WebView view, String url) {
Log.e(TAG, "onPageFinished..." + url);
super.onPageFinished(view, url);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null && (url.startsWith("http://") || url.startsWith(Constants.MEDIA_ENTRY_PROTOCOL + "://"))) {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
} else {
return false;
}
}
});
WebSettings webSettings = mArticleWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
if (BuildConfig.DEBUG) {
Log.d(TAG, "User Agent is " + webSettings.getUserAgentString());
}
}
The specific problem is onPageStarted
and the other overrides just stop getting called after a while. All the other code is reached, and the HTML generated looks fine.
Invalidating, reloading, re-initializing does not seem to do any good. It just dies and stays dead.
What else can I try? What else might be causing issues?
------------EDIT----------
After hours and hours of head bashing, and then discovering it is doing this outside of the pager as well, I am 90% certain I am hitting the issue linked below. That being said, I do not have a fix yet if anyone has any suggestions.
AdView bug causing all webviews stop loading when orientation changes and multi-threads are running?
----- FINAL EDIT ------- This never got 'fixed', we now load the ads via HTML rather than natively for Jelly Bean.
It is not:
Anything to do with the ViewPager
. Interstitial ads would also cause it eventually. Most of our ads were just in the ViewPager
.
A conflict between ActionBarSherlock
. Updating to AppCompat
didn't help anything.
A problem with just WebView
. Strange behavior was also noticed in XWalk
, including trying to load the ad in itself and then having flickering, scary weirdness, although XWalk
would recover after a bit. This was with both ActionBarSherlock
and AppCompat
.
My problem has nothing to do with rotation; I'm blaming threading in general. We do have a fair bit of threading going on.
We had an old version of Google Ads before (6.21). I updated to Google Play 7 before I even pointed my finger at ads causing the problem since it would be required. There was no behavior change in the update. AKA: PublisherAdView
and DfpAdView both react the same.
I am wondering if something happens to move the project to Android Studio, but have no idea what to point at.
At the end of the day this is an OS issue, but I don't know what in particular tickled it. I am very interested in hearing from anyone going through the same thing.
webView.loadUrl
without the base url things? – Joyann"http://www.example.com/"
? Is it local resource? Is it a website? What's in the extra HTML? This is odd. Does the website usejQuery Mobile
? – Joyann$.changePage('other.html', {changeHash: true})
on non-SPA websites makes the Android back button not work about 3 pages deep, but I guess that is not relevant here. If having to load HTML like that directly is unavoidable, then I'm out of ideas for the moment. – Joyann