Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clearing all cached items created by a WebView?

Tags:

android

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 following files:

/data
  /data
    /com.example.myapp
      /cache
        /webviewCache
          bunch of files here..
      /databases
        webview.db
        webviewCache.db

Is there any system call I can use to clear all the elements in /cache and /databases, or should we do that manually? I'm worried about doing it manually just because I don't know what new files WebView may leave behind in future versions of android so I won't be sure I'm really clearing everything for the user.

like image 564
user291701 Avatar asked Jul 01 '11 02:07

user291701


People also ask

Can I clear cache on android system Webview?

Tap on Storage. Tap the Clear cache and Clear data buttons to clear the cache and any other stored data.

Where is Webview cache stored?

webview cache is saved into /data/data/[your_package_name]/cache/org.


2 Answers

try this

mWebView.clearCache(true);
mContext.deleteDatabase("webview.db");
mContext.deleteDatabase("webviewCache.db");
like image 188
Mohammed Azharuddin Shaikh Avatar answered Sep 21 '22 15:09

Mohammed Azharuddin Shaikh


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.
like image 34
amalBit Avatar answered Sep 21 '22 15:09

amalBit