在Android的WebView / CookieSyncManager会话cookie的生命周期 [英] Lifecycle of a session cookie in an Android WebView / CookieSyncManager

查看:562
本文介绍了在Android的WebView / CookieSyncManager会话cookie的生命周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序它通过既有的WebView和HttpClient的发出请求到我的网络服务器。我同步使用CookieSyncManager两者之间饼干。到现在为止还挺好。

I have an Android application which makes requests to my webserver via both a WebView and an HttpClient. I sync cookies between the two using a CookieSyncManager. So far, so good.

在我的应用程序启动(内onResume()),我运行类似于下面的一块逻辑:

When my application starts (inside onResume()), I run a piece of logic similar to the following:

if ( appHasBeenIdleFor30Minutes() ) {
     CookieManager cookieManager = CookieManager.getInstance();
     cookieManager.removeSessionCookie();
     CookieSyncManager.getInstance().sync();
}

这个正确重置从用户的previous会议共设​​置任何会话cookie。我的问题是:将这种行为定期对自己发生这个问题(<一个href=\"http://stackoverflow.com/questions/10006334/android-webview-or-browser-not-deleting-session-cookies-on-device-reboot\">android web视图或浏览器不删除设备上的重启会话Cookie)似乎表明,事实并非如此。当我通过一个服务使用Cookie的同步时间的HttpClient看来会话Cookie不清除,从而导致奇怪的服务器端行为。

This correctly resets any session cookies that were set from the user's previous session. My question is: will this behavior happen periodically on its own? This question (android webview or browser not deleting session cookies on device reboot) seems to suggest that it does not. When I use the cookie-sync'd HttpClient via a Service it appears that session cookies are not cleared, thus resulting in strange server-side behavior.

我一直无法找到会话cookie的web视图/ CookieSyncManager里面的生命周期(过期时间= 0)的具体文件 - ?有其他人有更多的运气。

I've been unable to find concrete documentation on the lifecycle of session cookies (expiration time=0) inside a WebView/CookieSyncManager - has anyone else had more luck?

推荐答案

我直接从谷歌工程师,谁证实了我的怀疑得到了响应:

I received a response directly from a Google engineer, who confirmed my suspicions:

您是正确的,会话cookie不会自动在到期
  一个web视图的生命周期。
  如果您看到这个问题,你可以随时清除所有的
  饼干或空值显式地覆盖您的会话cookie。

You are correct, session cookies do not expire automatically in the lifecycle of a WebView. If you are seeing issues with this, you can always clear all of your cookies or overwrite your session cookies explicitly with an empty value.

在code你建议看起来像一个很好的解决方法,只是知道
  使用CookieSyncManager该cookie同步不同步 -
  在startSync(),stopSync()和同步()命令执行
  异步在后台线程。

The code you have suggested looks like a good workaround, just be aware that cookie synchronisation using a CookieSyncManager is not synchronous - the startSync(), stopSync() and sync() commands are executed asynchronously in a background thread.

TL; DR - 当关闭的WebView会话cookie不会过期,你就必须来管理自己

TL;DR - session cookies do not expire when a WebView closes, you'll have to manage that yourself.

这篇关于在Android的WebView / CookieSyncManager会话cookie的生命周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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