Elye
Elye

Reputation: 60251

Do I need to flush after setCookie in CookieManager?

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?

Upvotes: 5

Views: 4098

Answers (0)

Related Questions