How to save a cookie in an Android webview forever?

后端 未结 3 1751
悲哀的现实
悲哀的现实 2020-12-02 19:06

With my code below, I have been able to save a cookie, but as soon as I close the application the cookie disappears.

How is this caused and how can I solve it?

3条回答
  •  一生所求
    2020-12-02 20:06

    .sync() is to force a imediate sync ,and must be called after page load cause it sync RAM with cache , so cookie must be in ram before calling it .

    System automatically sync it every 5 mintues if you use this scheme

    onCreate: 
    CookieSyncManager.createInstance(context)
    
    onResume:
    CookieSyncManager.getInstance().startSync()
    
    onPause:
    CookieSyncManager.getInstance().stopSync()
    

    I think you did not waited 5 mintues so system save cookie.

提交回复
热议问题