Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 400
uTubeFan Avatar asked May 27 '11 18:05

uTubeFan


1 Answers

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?

like image 171
Torid Avatar answered Nov 14 '22 05:11

Torid