You are welcome. It sure will be useful for somebody. Just a quick note about your getCookie method: make sure to store the size of the 'cookies' list before the for loop. Not doing so forces the JVM to calculate the size of the list on each iteration.
More info here: http://developer.android.com/guide/practices/design/performance.html#foreach On 14 January 2011 17:54, lou <[email protected]> wrote: > Thank you Mohammed, but I've already seen these questions ! > I win ! I don't use onSaveInstanceState/onRestoreInstanceState because > I save the cookie in SharedPreferences when I receipt it , and restore > it if I have to create a new HttpClient. So my code : > > private static final String COOKIE_NAME = "my_cookie"; > > private void setCookie() { > CookieStore cookieStore = myDefaultHttpClient.getCookieStore(); > BasicClientCookie cookie = new BasicClientCookie(COOKIE_NAME, > cookieValue); // cookieValue is the value registered in > SharedPreferences > cookie.setPath("/"); > cookie.setDomain("my.domain.com"); > cookieStore.addCookie(cookie); > } > > public void getCookie() { > List<Cookie> cookies = > myDefaultHttpClient.getCookieStore().getCookies(); > for(int i = 0; i < cookies.size(); i++) { > if(cookies.get(i).getName().equals(COOKIE_NAME)) { > saveCookieInSharedPreferences(myActivity, COOKIE_NAME, > cookies.get(i).getValue()); > } > } > > Hope it can be useful for somebody ! > And thanks to Frederico & Mohammed for their answers ! > > On Jan 13, 2:07 pm, Mohammed Le Doze <[email protected]> > wrote: > > You might find help in the following stack overflow questions: > > > > - > > > http://stackoverflow.com/questions/3587254/how-do-i-manage-cookies-wi... > > - > > > http://stackoverflow.com/questions/2298889/robusteasy-way-to-save-res... > > > > Regards > > > > On 13 January 2011 11:48, lou <[email protected]> wrote: > > > > > > > > > > > > > > > > > > > > > Hi ! > > > I have an application using HttpClient, who saves automatically the > > > cookies received from the login request. > > > The matter : when an activity is killed, my httpClient is reseted, > > > consequently all next request are refused by the server cause the > > > cookies aren't sent. > > > What can I do ? > > > > > My suggestion : save the HttpClient in onSaveInstanceState(Bundle > > > outState), but I think it isn't possible > > > My other suggestion : get cookies ( I don't know how ! ) and save it > > > in onSaveInstancestate(...), and restore it in onRestoreInstanceState > > > > > Maybe these suggestions aren't the good solution. In all case, I need > > > a little bit of your help ! > > > Thanks in advance. > > > Louis C. > > > > > -- > > > You received this message because you are subscribed to the Google > > > Groups "Android Developers" group. > > > To post to this group, send email to > [email protected] > > > To unsubscribe from this group, send email to > > > [email protected]<android-developers%[email protected]><android-developers%2Bunsubs > [email protected]> > > > For more options, visit this group at > > >http://groups.google.com/group/android-developers?hl=en > > > > -- > > MLD > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected]<android-developers%[email protected]> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- MLD -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

