Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Methods](https://developer.android.com/reference/android/webkit/CookieSyncManager#pubmethods) \| [Protected Methods](https://developer.android.com/reference/android/webkit/CookieSyncManager#promethods) \| [Inherited Methods](https://developer.android.com/reference/android/webkit/CookieSyncManager#inhmethods)

# CookieSyncManager

*** ** * ** ***


`
public

final

class
CookieSyncManager
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


implements

https://developer.android.com/reference/java/lang/Runnable


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.webkit.CookieSyncManager |

<br />

*** ** * ** ***


**This class was deprecated
in API level 21.**   

The WebView now automatically syncs cookies as necessary.
You no longer need to create or use the CookieSyncManager.
To manually force a sync you can use the CookieManager
method `https://developer.android.com/reference/android/webkit/CookieManager#flush()` which is a synchronous
replacement for `https://developer.android.com/reference/android/webkit/CookieSyncManager#sync()`.

The CookieSyncManager is used to synchronize the browser cookie store
between RAM and permanent storage. To get the best performance, browser cookies are
saved in RAM. A separate thread saves the cookies between, driven by a timer.


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


To get instant sync instead of waiting for the timer to trigger, the host can
call


```
CookieSyncManager.getInstance().sync()
```


The sync interval is 5 minutes, so you will want to force syncs
manually anyway, for instance in `https://developer.android.com/reference/android/webkit/WebViewClient#onPageFinished(android.webkit.WebView,%20java.lang.String)`. Note that even sync() happens
asynchronously, so don't do it just as your activity is shutting
down.

## Summary

| ### Public methods ||
|---|---|
| ` static https://developer.android.com/reference/android/webkit/CookieSyncManager` | ` https://developer.android.com/reference/android/webkit/CookieSyncManager#createInstance(android.content.Context)(https://developer.android.com/reference/android/content/Context context) ` Create a singleton CookieSyncManager within a context |
| ` static https://developer.android.com/reference/android/webkit/CookieSyncManager` | ` https://developer.android.com/reference/android/webkit/CookieSyncManager#getInstance()() ` Singleton access to a `https://developer.android.com/reference/android/webkit/CookieSyncManager`. |
| ` void` | ` https://developer.android.com/reference/android/webkit/CookieSyncManager#resetSync()() ` *This method was deprecated in API level 1. Calling resetSync is no longer necessary as the WebView automatically syncs cookies.* |
| ` void` | ` https://developer.android.com/reference/android/webkit/CookieSyncManager#run()() ` When an object implementing interface `Runnable` is used to create a thread, starting the thread causes the object's `run` method to be called in that separately executing thread. |
| ` void` | ` https://developer.android.com/reference/android/webkit/CookieSyncManager#startSync()() ` *This method was deprecated in API level 1. Calling startSync is no longer necessary as the WebView automatically syncs cookies.* |
| ` void` | ` https://developer.android.com/reference/android/webkit/CookieSyncManager#stopSync()() ` *This method was deprecated in API level 1. Calling stopSync is no longer useful as the WebView automatically syncs cookies.* |
| ` void` | ` https://developer.android.com/reference/android/webkit/CookieSyncManager#sync()() ` *This method was deprecated in API level 1. Use `https://developer.android.com/reference/android/webkit/CookieManager#flush()` instead.* |

| ### Protected methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/webkit/CookieSyncManager#syncFromRamToFlash()() ` *This method is deprecated. Use `https://developer.android.com/reference/android/webkit/CookieManager#flush()` instead.* |

### Inherited methods

From class `

https://developer.android.com/reference/java/lang/Object

` `


https://developer.android.com/reference/java/lang/Object` `
https://developer.android.com/reference/java/lang/Object#clone()()
`

Creates and returns a copy of this object.


`


boolean` `
https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj)
`

Indicates whether some other object is "equal to" this one.


`


void` `
https://developer.android.com/reference/java/lang/Object#finalize()()
`

Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.


`


final

https://developer.android.com/reference/java/lang/Class<?>` `
https://developer.android.com/reference/java/lang/Object#getClass()()
`

Returns the runtime class of this `Object`.


`


int` `
https://developer.android.com/reference/java/lang/Object#hashCode()()
`

Returns a hash code value for the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notify()()
`

Wakes up a single thread that is waiting on this object's
monitor.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notifyAll()()
`

Wakes up all threads that are waiting on this object's monitor.


`


https://developer.android.com/reference/java/lang/String` `
https://developer.android.com/reference/java/lang/Object#toString()()
`

Returns a string representation of the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait()()
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*.


From interface `

https://developer.android.com/reference/java/lang/Runnable

` `
abstract


void` `
https://developer.android.com/reference/java/lang/Runnable#run()()
`

When an object implementing interface `Runnable` is used
to create a thread, starting the thread causes the object's
`run` method to be called in that separately executing
thread.


## Public methods

### createInstance

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static CookieSyncManager createInstance (Context context)
```

Create a singleton CookieSyncManager within a context

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/webkit/CookieSyncManager` | CookieSyncManager <br /> |

### getInstance

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static CookieSyncManager getInstance ()
```

Singleton access to a `https://developer.android.com/reference/android/webkit/CookieSyncManager`. An
IllegalStateException will be thrown if
`https://developer.android.com/reference/android/webkit/CookieSyncManager#createInstance(android.content.Context)` is not called before.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/webkit/CookieSyncManager` | CookieSyncManager <br /> |

### resetSync

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void resetSync ()
```


**This method was deprecated
in API level 1.**   

Calling resetSync is no longer necessary as the WebView automatically
syncs cookies.

resetSync() resets sync manager's timer.

<br />

### run

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void run ()
```

When an object implementing interface `Runnable` is used
to create a thread, starting the thread causes the object's
`run` method to be called in that separately executing
thread.


The general contract of the method `run` is that it may
take any action whatsoever.

<br />

### startSync

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void startSync ()
```


**This method was deprecated
in API level 1.**   

Calling startSync is no longer necessary as the WebView automatically
syncs cookies.

startSync() requests sync manager to start sync.

<br />

### stopSync

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void stopSync ()
```


**This method was deprecated
in API level 1.**   

Calling stopSync is no longer useful as the WebView
automatically syncs cookies.

stopSync() requests sync manager to stop sync. remove any SYNC_MESSAGE in
the queue to break the sync loop

<br />

### sync

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void sync ()
```


**This method was deprecated
in API level 1.**   

Use `https://developer.android.com/reference/android/webkit/CookieManager#flush()` instead.

sync() forces sync manager to sync now

<br />

## Protected methods

### syncFromRamToFlash

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void syncFromRamToFlash ()
```


**This method is deprecated.**   

Use `https://developer.android.com/reference/android/webkit/CookieManager#flush()` instead.

<br />

<br />