3

I'm using a WebView in an Android app. I periodically to be able to reset the WebView http session so that the server app it is accessing will initialise a new session. I can't find how to do this - is this possible ?

Rgds, Kevin.

Kevin
  • 11,361
  • 22
  • 79
  • 100

4 Answers4

17

I think the clear cookie can make session close. More about session

CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();
Ziem
  • 6,351
  • 7
  • 51
  • 85
Andrew Chen
  • 358
  • 3
  • 7
  • First line is deprecated / not needed. `removeAllCookie` method is deprecated too, we now use `removeAllCookies` (note the S at the end), sending a (nullable) callback function as parameter – Cesar Castro Aug 06 '20 at 19:37
3
import android.webkit.CookieManager;

CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeSessionCookie();

removeSessionCookie() allows to keep other cookies but clear sessions.

Rumit Patel
  • 4,807
  • 11
  • 42
  • 54
2

There are a couple of things you can do to clear the webview depending exactly what you want to do:

webView.clearCache(true);

webView.clearHistory();

webView.destroy();

Scoobler
  • 9,628
  • 4
  • 35
  • 51
0

This worked for me:

WebStorage.getInstance().deleteAllData()
grrigore
  • 988
  • 1
  • 20
  • 34