I\'m trying a simple app to read in the HTML of a website, and tranform it to create an easily readable UI in Android (This is an exersize in learning android, not to make a
CookieManager
is used by the Java's internal HTTP client. It has nothing to do with Apache HttpClient.
In your code you always create for each request a new instance of HttpClient
and therefore a new CookieStore
instance, which obviously gets garbage collected along with all cookies stored in as soon as that HttpClient
instance goes out of scope.
You should either
(1) Re-use the same instance of HttpClient
for all logically related HTTP requests and share it between all logically related threads (which is the recommended way of using Apache HttpClient)
(2) or, at the very least, share the same instance of CookieStore
between logically related threads
(3) or, if you insist on using CookieManager
to store all your cookies, create a custom CookieStore
implementation backed by CookieManager