i'm tring to show in webview page from local storage, it looks ok when page loaded first time, but when i remove webview and add it again it looks like on the picture (for 4.4+, on previous android versions just black screen):

webview adding progrommatcaly each time (using app context), switch off cache,cookies, and remove it in on destroy.
here is my code:
mLayout = (LinearLayout) view.findViewById(R.id.linear_main);
mWebView = new WebView(getActivity().getApplicationContext());
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setSaveFormData(false);
mWebView.setInitialScale(1);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setAppCacheEnabled(false);
mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
mWebView.getSettings().setDatabaseEnabled(false);
mWebView.getSettings().setDomStorageEnabled(false);
mWebView.getSettings().setGeolocationEnabled(false);
mWebView.getSettings().setSaveFormData(false);
mWebView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
mWebView.setWebChromeClient(new WebChromeClient());
if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
}
mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
mWebView.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);
mLayout.addView(mWebView,0);
/// then display page by call
public void display(String path){
Map<String, String> noCacheHeaders = new HashMap<String, String>(2);
noCacheHeaders.put("Pragma", "no-cache");
noCacheHeaders.put("Cache-Control", "no-cache");
mWebView.loadUrl(path, noCacheHeaders);
}
/// after display destroy fragment with the WebView
@Override
public void onDestroy() {
super.onDestroy();
CookieSyncManager.createInstance(getActivity().getApplicationContext());
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();
mWebView.removeAllViews();
mWebView.destroyDrawingCache();
mWebView.clearDisappearingChildren();
mWebView.clearFormData();
mWebView.clearHistory();
mWebView.clearCache(true);
mWebView.loadUrl("about:blank");
mWebView.pauseTimers();
mLayout.removeAllViews();
mWebView.destroy();
mWebView = null;
getActivity().getApplicationContext().deleteDatabase("webview.db");
getActivity().getApplicationContext().deleteDatabase("webviewCache.db");
}
could you please advice what else i need to try =)
looks that
mWebView.pauseTimers();
save data in some static variable... so, it doesen't matter that i've destroy webview and create new one, playing iframes were stopped. so, i've remove this line and it working now
be careful by using this flag
btw, guess it can related to memory leak issues.. but it's another story
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