目前遇到的情况是使用 WebView 打开某个 h5 界面,多数是打开正常的显示,但是偶然打开该界面内容会变得很小,像被缩小过一样。
做法是在打开 h5 界面,最后退出该 Activity 后要对 WebView 做清除。我的做法是:
private void clearCookie(){ CookieSyncManager.createInstance(this); //Create a singleton CookieSyncManager within a context CookieManager cookieManager = CookieManager.getInstance(); // the singleton CookieManager instance cookieManager.removeAllCookie();// Removes all cookies. if (Build.VERSION.SDK_INT < 21){ CookieSyncManager.getInstance().sync(); // forces sync manager to sync now }else{ cookieManager.flush(); } if (mWebMultiTime != null){ mWebMultiTime.setWebChromeClient(null); mWebMultiTime.setWebViewClient(null); mWebMultiTime.getSettings().setJavaScriptEnabled(false); mWebMultiTime.clearCache(true); } }