android webview cookie 同步时有时候会出现同步不成功的问题解决

博客内容指出,Android中使用`cookieManager.removeSessionCookie()`可能会遇到同步问题,因为该方法是异步的,可能导致在同步新Cookie时被删除。解决方案是在调用`removeSessionCookie()`后使用`SystemClock.sleep(500)`确保删除操作完成再进行同步,从而避免同步失败。
摘要由CSDN通过智能技术生成
这个问题不是随时重现,我们在同步之前会先删除所有之前的cookies,调用:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP /*&& method != null*/){cookieManager.removeSessionCookies(new ValueCallback() {@Overridepublic void onReceiveValue(Boolean value) {Log.d(TAG, "onReceiveValue value:"+value);}});}else{ cookieManager.removeSessionCookie();}

经过查阅n多stackoverflow后发现一个答案: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() i

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值