Android WebView清空缓存

Android原生和H5混合开发,要求用户退出登录后清空H5所有的缓存;

1、清空Cookie

        CookieSyncManager.createInstance(context.getApplicationContext());
        CookieManager cookieManager = CookieManager.getInstance();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            cookieManager.removeSessionCookies(null);
            cookieManager.removeAllCookie();
            cookieManager.flush();
        } else {
            cookieManager.removeSessionCookies(null);
            cookieManager.removeAllCookie();
            CookieSyncManager.getInstance().sync();
        }

2、清空Localstorage;

       清空H5保存在本地的所有内容;

WebStorage.getInstance().deleteAllData(); //清空WebView的localStorage

https://stackoverflow.com/questions/14653916/deleting-localstorage-but-still-persists

猜你喜欢

转载自blog.csdn.net/qq_35605213/article/details/82661347