我有一个代码将okHttp中的cookie写入CookieManager,如下所示。
@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();
}
我调用flush
,因为API如下所示。
/**
* 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();
但是,即使我删除它,似乎setCookie
本身已经被保留了。我还需要flush
吗?