title: Cookies take ±30 seconds to get stored on a Android device
body: <p>I have an Android app which loads a website in a WebView. The website has cookies which store various information.</p>
  
  <p>The cookies are created in the following way in C#:</p>
  
  <pre><code>Response.Cookies["city"].Expires = DateTime.MaxValue;
  </code></pre>
  
  <p><strong>Problem:</strong></p>
  
  <p>When the website loads in the WebView it takes aprox. 30 seconds for the cookies to get saved onto the Android device.</p>
  
  <p>If the user closes the application before ±30 seconds the cookies do not get stored on the Android device.</p>
  
  <p><strong>Question</strong></p>
  
  <p>How can I force and ensure that the cookies get saved to the Android device immediately when the website is opened in the webview?</p>
  
  <p><strong>What I've tried so far:</strong></p>
  
  <p>I've tried to implement the solution for this question but it did not help me. <a href="https://stackoverflow.com/questions/39842621/cookies-put-takes-30-seconds-to-save-the-cookie-on-disk-on-android">`$cookies.put()` takes 30 seconds to save the cookie on disk on Android</a></p>
  
  <p>I also tried removing the part from my Android code where it disables the cache but the problem still persists.</p>
  
  <p><strong>This is my Android Code that I have:</strong></p>
  
  <pre><code>@Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          mywebView = (WebView) findViewById(R.id.webView);
          mywebView.setBackgroundColor(Color.rgb(26,26,26));
          mywebView.setWebViewClient(new WebViewClient());
          WebSettings webSettings = mywebView.getSettings();
          webSettings.setJavaScriptEnabled(true);
          webSettings.setAppCacheEnabled(false);
          webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
          mywebView.setWebChromeClient(new WebChromeClient());
  
          if (Build.VERSION.SDK_INT &gt;= 21) {
              CookieManager cookieManager = CookieManager.getInstance();
              cookieManager.setAcceptThirdPartyCookies(mywebView, true);
              cookieManager.getInstance().flush();
          }
  
          mywebView.loadUrl("myURL");
          mywebView.setWebViewClient(new WebViewClient() {
              public boolean shouldOverrideUrlLoading(WebView view, String url) {
                  view.loadUrl(url);
                  return true;
              }
  
              @Override
              public void onPageStarted(WebView view, String url, Bitmap favicon) {
                  super.onPageStarted(view, url, favicon);
                  findViewById(R.id.progress1).setVisibility(View.GONE);
                  findViewById(R.id.progressBarMessage).setVisibility(View.GONE);
              }
          });
      }
  </code></pre>
  
  <p>Please advise how I can solve this problem. Thank you in advance.</p>