title: Java android - CookieHandler - How to keep cookies after closing the app?
body: <p>To keep cookies after each request in HttpURLConnection, should to add CookieHandler on the app starting:</p>
  
  <pre><code>CookieManager cookieManager = new CookieManager();
  CookieHandler.setDefault(cookieManager);
  </code></pre>
  
  <p>But in the app closing and opening again the cookies are empty...
  So how to save the cookies after the closing?</p>
  
  <p>Something like save them in the SharedPreferences or in the file and get them back after the opening...</p>
  
  <p>I tryed to keep them using CookieStore, but that's not worked:...</p>
  
  <p>Save:</p>
  
  <pre><code>Settings.Save(c, TAG, cookieManager.getCookieStore().getCookies().toString());
  </code></pre>
  
  <p>Load:</p>
  
  <pre><code>String load = Settings.Load(c, TAG);
  if (load != null) {
      for (HttpCookie hc : HttpCookie.parse(load)) {
          cookieManager.getCookieStore().add(new URI(Data.domain), hc);
      }
  }
  </code></pre>
  
  <p>Thanks..</p>