Android CookieManager fails to refresh cookies
<p>Curently in my Android app, I am using <code>CookieManager</code> and <code>CookieSyncManager</code>.
What I notice is that, the cookie is not updated properly.</p>

<p>For example:</p>

<pre><code>Android ----&gt; Server: No cookie
Server  ----&gt; Android: Cookie C1
Android ----&gt; Server: Cookie C1 (Correct)
Server  ----&gt; Android: Cookie C2
Android ----&gt; Server: Cookie C1 C2 (Incorrect)
</code></pre>

<p>Because of the 2 cookies returned, server side rejected the transaction.</p>

<p>I have tried to force sync, but the issue still persists.
I even tried to add some sleep, but it did not help either.</p>

<p>Any suggestion on what else I can try? </p>

<p>Thank a lot.</p>

<p>Regards
Andrew</p>

<pre><code>cookieManager = CookieManager.getInstance();

cookieInput = cookieManager.getCookie(Constants.HOST_URL);

write("Cookie from CookieManager 4:" + cookieInput);


cookieManager.removeAllCookie();

//SystemClock.sleep(2000);

cookieManager = CookieManager.getInstance();

cookieInput = cookieManager.getCookie(Constants.HOST_URL);

write("Cookie from CookieManager 5:" + cookieInput);


cookieManager.removeSessionCookie();

cookieManager.removeAllCookie();

//SystemClock.sleep(2000);

//CookieSyncManager.getInstance().sync();


cookieManager.setCookie(Constants.HOST_URL, cookieString);

cookieManager.setCookie(Constants.HOST_URL, cookieString1);

cookieManager.setCookie(Constants.HOST_URL, cookieString2);

//SystemClock.sleep(5000);

cookieManager = CookieManager.getInstance();

cookieInput = cookieManager.getCookie(Constants.HOST_URL);

write("Cookie from CookieManager 6:" + cookieInput); 


CookieSyncManager.getInstance().sync();

//SystemClock.sleep(30000);
</code></pre>
