是否需要CookieSyncManager的WebView的有效实例? [英] Does CookieSyncManager need a valid instance of WebView?
问题描述
我在我的应用程序)有点不寻常的情况中,我不能在的onCreate实例
而是仅后来在回调(即使不在同一线程)。的WebView
(
I have a somewhat unusual situation in my app in which I cannot instantiate WebView
in onCreate()
but rather only later on in a callback (not even on the same thread).
因此,俗套指令(没有双关语意)在官方文档,在其中你叫 CookieSyncManager.getInstance()。startSync()
在 Activity.onResume()
并不真正适用于我的情况。
As a result, the cookie cutter instructions (no pun intended) in the official documentation, in which you call CookieSyncManager.getInstance().startSync()
in Activity.onResume()
don't really apply in my situation.
这是因为 CookieSyncManager :: createInstance建立()需要被调用的
之前 CookieSyncManager ::的getInstance()
,但我的回调就是所谓的在 Activity.onResume()
(其中 CookieSyncManager ::的getInstance ()
被调用)。
This is because CookieSyncManager::createInstance()
needs to be called before CookieSyncManager::getInstance()
, but my callback is called after Activity.onResume()
(where CookieSyncManager::getInstance()
is called).
所以,我唯一的办法似乎移动 CookieSyncManager :: createInstance建立()
到 Activity.onResume()
,只打电话之前 CookieSyncManager ::的getInstance()
。
So my only recourse seems to move CookieSyncManager::createInstance()
to Activity.onResume()
, just before calling CookieSyncManager::getInstance()
.
这是不是一个真正的好的解决方案,因为除非我可以检查一个 CookieSyncManager
实例的存在,这不是一个好主意创建 CookieSyncManager
...的多个实例(它不会正常工作,反正)。
Which isn't really a good solution because, unless I can check for the existence of a CookieSyncManager
instance, it's not a good idea to create more than one instance of CookieSyncManager
... (it won't work properly anyway).
所以我想也许是移动 CookieSyncManager :: createInstance建立()
到的onCreate()
是完全在与官方文档线。唯一的问题是,实例的WebView
不的onCreate还不存在()
...
So I am thinking of perhaps move CookieSyncManager::createInstance()
to onCreate()
to be perfectly in line with the official documentation. The only problem is, an instance of WebView
doesn't exist yet in onCreate()
...
因此,我的问题:是否需要CookieSyncManager的WebView的有效实例
Hence my question: Does CookieSyncManager require a valid instance of WebView?
推荐答案
好了,你可以打电话CookieSyncManager创建的WebView对象之前,但随后你的WebView对象的饼干也不会被保存。
Well, You can call CookieSyncManager before creating a WebView object, but then your WebView object's cookies will not be saved either.
这篇关于是否需要CookieSyncManager的WebView的有效实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!