I have a cookie from the server and I save this cookie in a Shared Preference. When I send requests to the server from Ion library it goes right because I'm logged in the app and Ion has this cookie. And when I close the app and re-open, Ion has my cookie. The problem is when I destroyed the app, Ion doesn't have this cookie any more. And when I request a query to the server, it gives me a new one cookie and Ion has this new cookie. So, I need to establish the old cookie to the Ion library.
I've tried to set the cookie in the header:
String cookieString = ApiConstants.API_COOKIE_NAME + "=" + cookie;
headers.add(new BasicNameValuePair("Cookie", cookieString));
if (headers != null) {
for (int i = 0; i < headers.size(); i++) {
b = b.addHeader(headers.get(i).getName(), headers.get(i).getValue());
}
}
And I've tried to add this cookie to the CookieManager:
CookieManager cookieManager = CookieManager.getInstance();
CookieSyncManager.createInstance(context);
cookieManager.setAcceptCookie(true);
cookieManager.setCookie(ApiConstants.BASIC_ROOT_URL, cookieString);
CookieSyncManager.getInstance().sync();
But, none of this tried have gone, someone can help me?