CookieSyncManager::createInstance() needs to be called before CookieSyncManager::getInstance()

╄→гoц情女王★ 提交于 2019-12-18 11:56:54

问题


This error message is pretty clear:

CookieSyncManager::createInstance() needs to be called before CookieSyncManager::getInstance()

But I only get this error because I followed the official documentation:

To use the CookieSyncManager, the host application has to call the following when the application starts:

CookieSyncManager.createInstance(context)

To set up for sync, the host application has to call

CookieSyncManager.getInstance().startSync()

in Activity.onResume()

The error occurs only when the application attempts to resume, not when it starts cleanly.

So, I can probably fix that by moving CookieSyncManager.createInstance(context) to Activity.onResume() but... won't that create a new problem?

(for example, forgetting the previous session cookies every time the app resumes?)


回答1:


I followed the official documentation in one of recent apps and CookieSyncMasnager is working just fine...

I have the following:

onCreate()
    CookieSyncManager.createInstance(this);

onResume()
    CookieSyncManager.getInstance().startSync();

onPause()
    CookieSyncManager.getInstance().stopSync();

I am using the activity context in the createInstance(). You don't mention which context you're using?

You also don't mention doing a CookieSyncManager.getInstance().stopSync() in onPause() (or similar). So perhaps for a resume you are calling CookieSyncManager.getInstance().startSync() twice without an intervening stop?



来源:https://stackoverflow.com/questions/6156514/cookiesyncmanagercreateinstance-needs-to-be-called-before-cookiesyncmanager

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