To keep cookies after each request in HttpURLConnection, should to add CookieHandler on the app starting:
CookieManager cookieManager = new CookieManager();
CookieHandler.setDefault(cookieManager);
But in the app closing and opening again the cookies are empty... So how to save the cookies after the closing?
Something like save them in the SharedPreferences or in the file and get them back after the opening...
I tryed to keep them using CookieStore, but that's not worked:...
Save:
Settings.Save(c, TAG, cookieManager.getCookieStore().getCookies().toString());
Load:
String load = Settings.Load(c, TAG);
if (load != null) {
for (HttpCookie hc : HttpCookie.parse(load)) {
cookieManager.getCookieStore().add(new URI(Data.domain), hc);
}
}
Thanks..
sharedPreference
? They perfectly fit your requirement – Mcmurray