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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM