Cookies & Webview - CookieSyncManager in Android!

前端 未结 2 435
生来不讨喜
生来不讨喜 2020-12-16 20:56

I have an activity that lets you sign in to a page. In the next activity it should display a webpage based on the cookie if the login was successful. The cookie is retrived

2条回答
  •  伪装坚强ぢ
    2020-12-16 21:37

    You have used this line -

     if (sessionCookie != null) {
                              cookieManager.removeSessionCookie();
    
      }
    

    . To ensure you receive new cookie everytime.

    Seems like you have gone through same issue as I faced, check below link -

    removeSessionCookie() issue of android (code.google.com)

    it says that removeSessionCookie() is implemented in a thread, so whenever it is called; a thread starts and after your setCookie(url, cookieString); is called, it removes the new cookie you just set. So for some devices it works well as removeSessionCookie() is already executed, while, for some, it remove the cookie, and we get that problem.

    by using SystemClock.sleep(500); , you just gave system to finish removeSessionCookie() first

    I suggest you remove this removeSessionCookie(); as you are setting only one cookie, so it won't conflict with other cookies. Your code will work seamlessly.

提交回复
热议问题