0

I'm hoping someone can shed some light on this for me as I am a bit confused as to the "why" of it all. I am using a WebView in my application but I am finding that it is not always correctly syncing my cookies. I have looked at multiple code examples for the CookieSyncManager and they all say to call CookieSyncManager.getInstance().stopSync(); from within onResume(). My question is, if my application is being resumed why would I want to stop syncing cookies? Shouldn't I be calling CookieSyncManager.getInstance().stopSync(); in onPause() since my application is losing focus and there won't be anything to sync? Am I just not understanding the way this works properly?

Here is one of the code examples I'm speaking of. It seems like most other examples I see use the same or similar code.

http://developer.android.com/reference/android/webkit/CookieSyncManager.html

forcedfx
  • 3,388
  • 1
  • 12
  • 8

1 Answers1

0

Ok, so I've come to find out that the documentation I posted is correct. I apparently just have trouble reading. But it seems I'm not alone as other tutorials have made the same mistake because of the way the documentation is laid out.

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(), and call

CookieSyncManager.getInstance().stopSync()

in Activity.onPause().

Personally, I think it makes more sense to write it this way.

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's Activity.onResume() has to call

CookieSyncManager.getInstance().startSync()

And then to stop syncing the application's Activity.onPause() has to call

CookieSyncManager.getInstance().stopSync()

Live and learn.

forcedfx
  • 3,388
  • 1
  • 12
  • 8