5

I have a code that writes the cookies from okHttp to CookieManager as below.

@Override
public void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
    CookieManager webviewCookieManager = CookieManager.getInstance();
    String urlString = url.toString();

    for (Cookie cookie : cookies) {
        webviewCookieManager.setCookie(urlString, cookie.toString());
    }
    webviewCookieManager.flush();
}

I call flush as the API reads as below.

/**
 * Ensures all cookies currently accessible through the getCookie API are
 * written to persistent storage.
 * This call will block the caller until it is done and may perform I/O.
 */
public abstract void flush();

However, even if I remove it, seems like setCookie itself is already persisted. Do I still need flush?

Elye
  • 53,639
  • 54
  • 212
  • 474
  • 2
    I was wondering the same thing, http://innodroid.com/blog/post/webview-cookies-headers-and-user-agent is explaining this a bit better. – SeikoTheWiz Aug 08 '18 at 12:53

0 Answers0