android - share session between two webviews?

余生长醉 提交于 2019-12-22 11:27:44

问题


first of all, can someone please explain how does CookieManager.getInstance() work? I don't really get how I can get the session from webview? Lets say if I have this

CookieSyncManager.createInstance(WebviewPage.this);
CookieManager cookieManager = CookieManager.getInstance();

Do I get the session from the class named WebviewPage? but what if I named my actual WebView to webview, how can cookieManager get the session of webview? not even talk about if I had two WebView, webview1 and webview2. How do I know which session that was stored in cookieManager??

My main question is...I have two activities and one webview in each activity. How can I get the session from Activity A and pass it to the webview in Activity B?

Thanks!!!


回答1:


As far as I know, you don't need to set cookie for webview2. webview2 will automatically use the cookies from webview1.




回答2:


CookieManager seems to be a singleton, so when you call getInstance() you always get the same instance. So if webview 1 set some cookies on the CookieManager, or if you set it your self using set Cookie, all other webviews should get the same cookies as well.



来源:https://stackoverflow.com/questions/17228701/android-share-session-between-two-webviews

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!