uTubeFan
uTubeFan

Reputation: 6794

Does CookieSyncManager need a valid instance of 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).

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.

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).

So my only recourse seems to move CookieSyncManager::createInstance() to Activity.onResume(), just before calling CookieSyncManager::getInstance().

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).

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()...

Hence my question: Does CookieSyncManager require a valid instance of WebView?

Upvotes: 1

Views: 1140

Answers (1)

an00b
an00b

Reputation: 11468

Well, You can call CookieSyncManager before creating a WebView object, but then your WebView object's cookies will not be saved either.

Upvotes: 1

Related Questions