@Nullable @Override @SuppressWarnings("deprecation") @SuppressLint("SetJavaScriptEnabled") public View onCreateView2(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { Context context = getContext2(); AssertUtils.assertNotNull(context); EhUtils.signOut(context); // http://stackoverflow.com/questions/32284642/how-to-handle-an-uncatched-exception CookieManager cookieManager = CookieManager.getInstance(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { cookieManager.flush(); cookieManager.removeAllCookies(null); cookieManager.removeSessionCookies(null); } else { CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(context); cookieSyncManager.startSync(); cookieManager.removeAllCookie(); cookieManager.removeSessionCookie(); cookieSyncManager.stopSync(); } mWebView = new WebView(context); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.setWebViewClient(new LoginWebViewClient()); mWebView.loadUrl(EhUrl.URL_SIGN_IN); return mWebView; }
cookieManager.removeAllCookie(); cookieManager.removeSessionCookie(); cookieSyncManager.stopSync();
/** * {@inheritDoc} */ @Override public void onPause() { // Un-register the connectivity changed receiver unregisterReceiver(mConnectivityReceiver); if (mWebView != null) { // Pass lifecycle events to the WebView mWebView.onPause(); } if (mCookieSyncManager != null) { // Stop synchronizing the CookieSyncManager mCookieSyncManager.stopSync(); } super.onPause(); }
@Override protected void onPause() { if (implementation != null) { WebviewUtil.onPause(implementation.getWebView()); } CookieSyncManager csm = CookieSyncManager.getInstance(); if (csm != null) csm.stopSync(); super.onPause(); }
/** * dammit, android. stolen from: * https://stackoverflow.com/questions/28998241/how-to-clear-cookies-and-cache-of-webview-on-android-when-not-in-webview */ @SuppressWarnings("deprecation") protected void clearCookies(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { CookieManager.getInstance().removeAllCookies(null); CookieManager.getInstance().flush(); } else { CookieSyncManager cookieSyncMngr=CookieSyncManager.createInstance(context); cookieSyncMngr.startSync(); CookieManager cookieManager=CookieManager.getInstance(); cookieManager.removeAllCookie(); cookieManager.removeSessionCookie(); cookieSyncMngr.stopSync(); cookieSyncMngr.sync(); } } }
/** * Clear the cookies */ @SuppressWarnings("deprecation") public void clearCookies() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { CookieManager.getInstance().removeAllCookies(null); CookieManager.getInstance().flush(); } else { CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(getContext()); cookieSyncMngr.startSync(); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); cookieManager.removeSessionCookie(); cookieSyncMngr.stopSync(); cookieSyncMngr.sync(); } }