title: Android CookieManager setCookie creates multiple cookies
body: <p>In my android application I have a webview. It loads URLs from multiple domains. I need to delete all cookies from a specific domain. I want to keep cookies from other domains. But I need to delete all cookies from one domain.  I'm open to all other solutions that handles my request. (note that domain uses both http and https)</p>
  
  <p>But when I try to use CookieManager.setCookie, all available cookies for that domain didn't deleted. Multiple cookie keys appeear when I try to write to that keys.</p>
  
  <p>I attach my code below. You can find results in comment lines. At the end of story I get this cookie. Note for multiple values:</p>
  
  <pre><code>"userid=12%34; token=12ased; remember_check=0; userid='-1'; token='-1'; remember_check='-1';"
  </code></pre>
  
  <p>My helper function that splits cookie string to get cookie keys:</p>
  
  <pre><code>public static Vector&lt;String&gt; getCookieAllKeysByCookieString(String pCookies) {
      if (TextUtils.isEmpty(pCookies)) {
          return null;
      }
      String[] cookieField = pCookies.split(";");
      int len = cookieField.length;
      for (int i = 0; i &lt; len; i++) {
          cookieField[i] = cookieField[i].trim();
      }
      Vector&lt;String&gt; allCookieField = new Vector&lt;String&gt;();
      for (int i = 0; i &lt; len; i++) {
          if (TextUtils.isEmpty(cookieField[i])) {
              continue;
          }
          if (!cookieField[i].contains("=")) {
              continue;
          }
          String[] singleCookieField = cookieField[i].split("=");
          allCookieField.add(singleCookieField[0]);
      }
      if (allCookieField.isEmpty()) {
          return null;
      }
      return allCookieField;
  }
  </code></pre>
  
  <p>I get present cookies:</p>
  
  <pre><code>// I take cookie string for specific URL
  mCookieManager = CookieManager.getInstance();
  String url2="https://mysite.com";
  String cookieString = mCookieManager.getCookie(url2);
  Toast.makeText(mContext, "cookie string:\n"+cookieString, Toast.LENGTH_SHORT).show();
  // result is: userid=12%34; token=12ased; remember_check=0;
  </code></pre>
  
  <p>Then I call to replace old cookies.</p>
  
  <pre><code>Vector&lt;String&gt; cookie = CookieUtil.getCookieAllKeysByCookieString(cookieString);
  if (cookie == null || cookie.isEmpty()) {
      Toast.makeText(mContext, "cookie null", Toast.LENGTH_SHORT).show();
  }
  if (cookie != null) {
      int len = cookie.size();
      Toast.makeText(mContext, "cookie number: "+len, Toast.LENGTH_SHORT).show();
      // result is, cookie number: 3
      String cookieNames="";
      for (int i = 0; i &lt; len; i++) {
          cookieNames += "\n"+cookie.get(i) ;
          mCookieManager.setCookie(url2, cookie.get(i) + "='-1';");
      }
      Toast.makeText(mContext, "cookieNames:\n"+cookieNames, Toast.LENGTH_SHORT).show();
      // result is: "cookienames: userid token remember_check"
  
      mCookieSyncManager.sync();
  
      cookieString = mCookieManager.getCookie(url2);
      Toast.makeText(mContext, "cookie string:\n"+cookieString, Toast.LENGTH_SHORT).show();
      mCookieSyncManager.sync();
      // result is: "userid=12%34; token=12ased; remember_check=0; userid='-1'; token='-1'; remember_check='-1';"
  }
  </code></pre>
  
  <p>Edit:<br>
  I also tried setCookie like this:</p>
  
  <pre><code>mCookieManager.setCookie(url2, cookie.get(i) + "=-1;");
  mCookieManager.setCookie(url2, cookie.get(i) + "=-1");
  </code></pre>
  
  <p>Edit2: setCookie's signature is like this:</p>
  
  <pre><code> /**
   * Sets a cookie for the given URL. Any existing cookie with the same host,
   * path and name will be replaced with the new cookie. The cookie being set
   * must not have expired and must not be a session cookie, otherwise it
   * will be ignored.
   *
   * @param url the URL for which the cookie is set
   * @param value the cookie as a string, using the format of the 'Set-Cookie'
   *              HTTP response header
   */
  public void setCookie(String url, String value) {
      throw new MustOverrideException();
  }
  </code></pre>
  
  <p>Although I get same keys inside cookie string (<code>"userid=12%34; token=12ased; remember_check=0; userid='-1'; token='-1'; remember_check='-1';"</code>) will they have different host or path ?</p>