Android: How to store cookies?

Use a CookieSyncManager to store your cookie value. It can persist across application starts.

Beware of using CookieSyncManager inside of WebViewClient#shouldInterceptRequest on KitKat. It will deadlock.

EDIT

CookieSyncManager was deprecated in API 21:

This class was deprecated in API level 21. The WebView now
automatically syncs cookies as necessary. You no longer need to create
or use the CookieSyncManager. To manually force a sync you can use the
CookieManager method flush() which is a synchronous replacement for
sync().

Leave a Comment