CookieManager is abstract, cannot be instantiated. Why?

1.3k views Asked by At
OkHttpClient client = new OkHttpClient();
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);

throws "CookieManager is abstract, cannot be instantiated"

I'm importing android.webkit.CookieManager and everything seems fine from the documentation side.

1

There are 1 answers

0
Robin Dijkhof On BEST ANSWER

Because the cookiemanager manages all the cookies, you can not create intances of it. That would mean one instance got different cookies that another. The cookiemanager is therefor a so called singleton. Use CookieManager cookieManager = CookieManager.getInstance() You can look it up here