Lifecycle of a session cookie in an Android WebView / CookieSyncManager

后端 未结 1 1718
花落未央
花落未央 2021-02-02 03:13

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 goo

1条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-02 03:20

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

    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.

    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 - session cookies do not expire when a WebView closes, you'll have to manage that yourself.

    0 讨论(0)
提交回复
热议问题