。CookieManager.getInstance()removeAllCookie();不会删除所有cookie [英] CookieManager.getInstance().removeAllCookie(); doesn't remove all cookies

查看:2677
本文介绍了。CookieManager.getInstance()removeAllCookie();不会删除所有cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我叫CookieManager.getInstance()中的onCreate removeAllCookie()在我的应用程序。

I call CookieManager.getInstance().removeAllCookie() in onCreate in my app.

我运行到那里,我看到了一个GET请求意想不到的cookie值获取传递了一个奇怪的问题。事实上,cookie的值是真的,真的很旧值。

I'm running into a weird issue where I'm seeing an unexpected cookie value get passed up in a GET request. In fact, the cookie value is a really, really old value.

下面是步骤我为测试执行:

Here are the steps I perform for the test:


  1. 安装应用程序

  2. 请在应用程序启动的GET请求。请求应干净:没有饼干应发送了

  3. 的GET请求有一个Set-Cookie响应。该值是基于请求时间,所以有一个很小的机会,这值是任何两个请求相同的。

  4. 请另一个GET请求。请求应该从第3步发送了cookie的值。

我第一次安装的应用程序,该cookie行为的工作就像我上面的预期。我卸载应用程序,然后重新安装,以及Cookie行为,再次担任预期。我这样做了几次,一切都很好,很正常。

The first time I installed the app, the cookie behavior worked as I expected above. I uninstalled the app, then re-installed it, and the cookie behavior, again, worked as expected. I do this a few times, things are fine and dandy.

突然,第N安装,第2步不及格。的第一GET请求不干净。事实上,它的进入与被在第一安装该应用的设置的值。

Then, suddenly, on the Nth install, step 2 doesn't pass. The very first GET request isn't clean. In fact, it's comes in with a value that was set on the first install of the app.

我不能可靠地重现此问题,但我看到它往往。这并不是说上安装的第一个GET请求被发送了从马上previous cookie的值设置 - 值是从三个或四个previous安装这都是其次的卸载

I can't reproduce this problem reliably, but I do see it quite often. It's not that the first GET request on install is sending up a cookie value from the immediately previous install -- the value is from three or four previous installs which were all followed by uninstalls.

这怎么可能,我看到这个?我怎么能实际的删除所有应用程序的饼干?

How is it possible that I'm seeing this? How can I actually remove all of the app's cookies?

推荐答案

这是一个在黑暗中拍摄,但也许从你的第一个饼干装在永久存储,而来自重新安装那些在RAM进行高速缓存。也许删除所有cookie的作用没有被sync'ed出于某种原因永久存储,因此它保持周围重新安装的旧值。

This is a shot in the dark, but maybe the cookies from your first install are in persistent storage, while the ones from reinstalls are cached in the RAM. Maybe the action of removing all cookies is not being sync'ed to persistent storage for some reason, so it keeps the old values around between reinstalls.

引用的文档的<一个href=\"http://developer.android.com/reference/android/webkit/CookieSyncManager.html\"><$c$c>CookieSyncManager (重点煤矿):

Quoting the docs for CookieSyncManager (emphasis mine):

的CookieSyncManager用于同步RAM和永久存储之间的浏览器cookie存储。为了获得最佳性能,浏览器的cookies保存在RAM中。 A 单独的线程节约之间,由计时器驱动的cookie。

The CookieSyncManager is used to synchronize the browser cookie store between RAM and permanent storage. To get the best performance, browser cookies are saved in RAM. A separate thread saves the cookies between, driven by a timer.

...

同步间隔为5分钟,所以你会希望强制手动同步无论如何,例如在onPageFinished(WebView中,字符串)。请注意,即使同步()发生的异步,所以不这样做,就像你的活动被关闭

The sync interval is 5 minutes, so you will want to force syncs manually anyway, for instance in onPageFinished(WebView, String). Note that even sync() happens asynchronously, so don't do it just as your activity is shutting down.

这有力地表明,也许(在您的测试中,我假设在不到5分钟的间隔有时做),当应用程序卸载它尚未sync'ed,所以从第一个安装旧值分别为仍然在此时持久存储。我也没有理由认为将同步在卸载过程中,如果间隔5分钟没有通过发生。

That strongly suggests that maybe (on your tests, which I assume were sometimes made in intervals of less than 5 minutes) when the app was uninstalled it hadn't sync'ed yet, so the old values from the first install were still in the persistent storage at this point. I have also no reason to assume that sync would happen during an uninstall if the 5 minutes interval hadn't passed.

这使得一个问题:为什么有时即使你在的onCreate 清除他们一些cookie发送?原来, removeAllCookie < STRONG>也是异步 - 有时你做你之前第一个请求,有时不会,而在后一种情况下,它会发送依然活跃值,将已经完成:从你的人第一次安装,仍处于持久化存储。

That leaves one question: why sometimes some cookies are sent even though you cleared them in onCreate? It turns out the removeAllCookie is also asynchronous - sometimes it will have completed before you make your first request, sometimes it will not, and in the latter case it will send the values that are still active: the ones from your first install, that are still in persistent storage.

(请注意,我还在学习Android开发,和我的一些假设可能是错的 - 如何饼干的管理和对不论是否在一个国家中的activity's生命周期可能仍然未完成时,另外一个运行;但这间pretation是pretty与您所描述的行为)一致

(Please note that I'm still learning Android development, and some of my assumptions might be wrong - about how cookies are managed and about whether or not an asynchronous call made in one state in the activity's lifecycle might still be unfinished when another one runs; but this interpretation is pretty consistent with the behavior you're describing)

这篇关于。CookieManager.getInstance()removeAllCookie();不会删除所有cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆