Clearing all cached items created by a WebView?

后端 未结 3 1463
借酒劲吻你
借酒劲吻你 2021-01-05 01:16

I\'ve got a WebView in my app. When the user logs out of my app, I\'d like to delete all cached resources the WebView may have created. Looking at an emulator, I see the fol

相关标签:
3条回答
  • 2021-01-05 01:39

    try this

    mWebView.clearCache(true);
    mContext.deleteDatabase("webview.db");
    mContext.deleteDatabase("webviewCache.db");
    
    0 讨论(0)
  • 2021-01-05 01:43

    This is the only code that saved my day!!

     CookieSyncManager.createInstance(this);         
     CookieManager cookieManager = CookieManager.getInstance();        
     cookieManager.removeAllCookie();
    

    My scenario:

    • Once logged in via linkedIn with the webview. The webview saves the login details. I need my app to clear this when the user signs out of the application. All the other approaches did not work for me.
    0 讨论(0)
  • 2021-01-05 01:53

    Only posting here because commenting can be ugly

    clearCache() will work because:

    From the doc:

    Clear the resource cache. Note that the cache is per-application, so this will clear the cache for all WebViews used.

    0 讨论(0)
提交回复
热议问题