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,521
  • 22
  • 81
  • 103

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,579
  • 8
  • 53
  • 86
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
  • 8,830
  • 18
  • 51
  • 70
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,696
  • 4
  • 36
  • 51
0

This worked for me:

WebStorage.getInstance().deleteAllData()
grrigore
  • 1,050
  • 1
  • 21
  • 39