0

I have an android application that has native framework and content itself is presented in web format and in webview. The meaning of the application is to allow users to use the device using predefined services that may require autentication.

How ever when I try to clean up the webview caches after user has completed his/her tasks the webview will remember everything and all e.g. login credentials are in place, history remains etc.

I have tried the following to do the clean up without any success, what I am missing in this ?

(wvfo if the overlay fragment in which the webview is that each service is using)

wvfo.getWebView().clearCache(true);
wvfo.getWebView().clearFormData();
wvfo.getWebView().clearHistory();
wvfo.getWebView().clearMatches();
// wvfo.getWebView().setWebViewClient(new WebViewClient());
// wvfo.loadUrl("javascript:document.open();document.close();");
CookieManager.getInstance().removeAllCookies(null);
CookieManager.getInstance().flush();  
wvfo.destroyWebview();

Any ideas what is wrong with this and why the history doesn't get cleared ?

Thanks in advance

braX
  • 11,506
  • 5
  • 20
  • 33
Androider
  • 1
  • 1

1 Answers1

0

Yes, You have to delete webview default DB also. Check the below code.

static void clearWebViewAllCache(Context context, WebView webView) {
try {
AgentWebConfig.removeAllCookies(null);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
context.deleteDatabase("webviewCache.db");
context.deleteDatabase("webview.db");
webView.clearCache(true);
webView.clearHistory();
webView.clearFormData();
clearCacheFolder(new File(AgentWebConfig.getCachePath(context)), 0);
} catch (Exception ignore) {
//ignore.printStackTrace();
if (AgentWebConfig.DEBUG) {
  ignore.printStackTrace();
}
}
}

I hope, this will help you.

Happy codding...

Pratik Satani
  • 1,115
  • 1
  • 9
  • 25
  • Thanks, it was the missing peace – Androider Dec 30 '19 at 11:08
  • HI again,actually this still didn't solve all the problems. This solution still does leave the ww-page search - field words in memory, how can i remove these too ? Where are those located and how to delete those too ? – Androider Jan 02 '20 at 08:36
  • try this : https://stackoverflow.com/questions/2465432/android-webview-completely-clear-the-cache?rq=1 May be this will work – Pratik Satani Jan 02 '20 at 12:53
  • Hi, this didn't work either. I am not sure if this is related to the old version of android. problem occurs in android 7 platform, if i use e.g samsung 8.0 or later android version tablets this works fine. – Androider Jan 04 '20 at 14:04