问题
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