Added in [API level 5](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter#constants) \| [Ctors](https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter#pubctors) \| [Methods](https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter#inhmethods)

# AbstractThreadedSyncAdapter

*** ** * ** ***

` public abstract class AbstractThreadedSyncAdapter `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

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

<br />

*** ** * ** ***

An abstract implementation of a SyncAdapter that spawns a thread to invoke a sync operation. If a sync operation is already in progress when a sync request is received, an error will be returned to the new request and the existing request will be allowed to continue. However if there is no sync in progress then a thread will be spawned and `https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter#onPerformSync(android.accounts.Account,%20android.os.Bundle,%20java.lang.String,%20android.content.ContentProviderClient,%20android.content.SyncResult)` will be invoked on that thread.

Syncs can be cancelled at any time by the framework. For example a sync that was not user-initiated and lasts longer than 10 minutes will be considered timed-out and cancelled. Similarly the framework will attempt to determine whether or not an adapter is making progress by monitoring its network activity over the course of a minute. If the network traffic over this window is close enough to zero the sync will be cancelled. You can also request the sync be cancelled via `https://developer.android.com/reference/android/content/ContentResolver#cancelSync(android.accounts.Account,%20java.lang.String)` or `https://developer.android.com/reference/android/content/ContentResolver#cancelSync(android.content.SyncRequest)`.

A sync is cancelled by issuing a `https://developer.android.com/reference/java/lang/Thread#interrupt()` on the syncing thread. **Either your code in `https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter#onPerformSync(android.accounts.Account,%20android.os.Bundle,%20java.lang.String,%20android.content.ContentProviderClient,%20android.content.SyncResult)` must check `https://developer.android.com/reference/java/lang/Thread#interrupted()`, or you you must override one of `https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter#onSyncCanceled(java.lang.Thread)`/`https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter#onSyncCanceled()`** (depending on whether or not your adapter supports syncing of multiple accounts in parallel). If your adapter does not respect the cancel issued by the framework you run the risk of your app's entire process being killed.

In order to be a sync adapter one must extend this class, provide implementations for the abstract methods and write a service that returns the result of `https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter#getSyncAdapterBinder()` in the service's `https://developer.android.com/reference/android/app/Service#onBind(android.content.Intent)` when invoked with an intent with action `android.content.SyncAdapter`. This service must specify the following intent filter and metadata tags in its AndroidManifest.xml file

```
  <intent-filter>
    <action android:name="android.content.SyncAdapter" />
  </intent-filter>
  <meta-data android:name="android.content.SyncAdapter"
            android:resource="@xml/syncadapter" />
```
The `android:resource` attribute must point to a resource that looks like:

```
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
   android:contentAuthority="authority"
   android:accountType="accountType"
   android:userVisible="true|false"
   android:supportsUploading="true|false"
   android:allowParallelSyncs="true|false"
   android:isAlwaysSyncable="true|false"
   android:syncAdapterSettingsAction="ACTION_OF_SETTINGS_ACTIVITY"
/>
```

- The `android:contentAuthority` and `android:accountType` attributes indicate which content authority and for which account types this sync adapter serves.
- `android:userVisible` defaults to true and controls whether or not this sync adapter shows up in the Sync Settings screen.
- `android:supportsUploading` defaults to true and if true an upload-only sync will be requested for all syncadapters associated with an authority whenever that authority's content provider does a `https://developer.android.com/reference/android/content/ContentResolver#notifyChange(android.net.Uri,%20android.database.ContentObserver,%20boolean)` with syncToNetwork set to true.
- `android:allowParallelSyncs` defaults to false and if true indicates that the sync adapter can handle syncs for multiple accounts at the same time. Otherwise the SyncManager will wait until the sync adapter is not in use before requesting that it sync an account's data.
- `android:isAlwaysSyncable` defaults to false and if true tells the SyncManager to initialize the isSyncable state to 1 for that sync adapter for each account that is added.
- `android:syncAdapterSettingsAction` defaults to null and if supplied it specifies an Intent action of an activity that can be used to adjust the sync adapter's sync settings. The activity must live in the same package as the sync adapter.

<br />

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter#LOG_SYNC_DETAILS` *This constant was deprecated in API level 15. Private constant. May go away in the next release.* |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter#AbstractThreadedSyncAdapter(android.content.Context,%20boolean)(https://developer.android.com/reference/android/content/Context context, boolean autoInitialize) ` Creates an `https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter`. |
| ` https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter#AbstractThreadedSyncAdapter(android.content.Context,%20boolean,%20boolean)(https://developer.android.com/reference/android/content/Context context, boolean autoInitialize, boolean allowParallelSyncs) ` Creates an `https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter`. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/content/Context` | ` https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter#getContext()() ` |
| ` final https://developer.android.com/reference/android/os/IBinder` | ` https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter#getSyncAdapterBinder()() ` |
| ` abstract void` | ` https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter#onPerformSync(android.accounts.Account,%20android.os.Bundle,%20java.lang.String,%20android.content.ContentProviderClient,%20android.content.SyncResult)(https://developer.android.com/reference/android/accounts/Account account, https://developer.android.com/reference/android/os/Bundle extras, https://developer.android.com/reference/java/lang/String authority, https://developer.android.com/reference/android/content/ContentProviderClient provider, https://developer.android.com/reference/android/content/SyncResult syncResult) ` Perform a sync for this account. |
| ` void` | ` https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter#onSecurityException(android.accounts.Account,%20android.os.Bundle,%20java.lang.String,%20android.content.SyncResult)(https://developer.android.com/reference/android/accounts/Account account, https://developer.android.com/reference/android/os/Bundle extras, https://developer.android.com/reference/java/lang/String authority, https://developer.android.com/reference/android/content/SyncResult syncResult) ` Report that there was a security exception when opening the content provider prior to calling `https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter#onPerformSync(android.accounts.Account,%20android.os.Bundle,%20java.lang.String,%20android.content.ContentProviderClient,%20android.content.SyncResult)`. |
| ` void` | ` https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter#onSyncCanceled(java.lang.Thread)(https://developer.android.com/reference/java/lang/Thread thread) ` Indicates that a sync operation has been canceled. |
| ` void` | ` https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter#onSyncCanceled()() ` Indicates that a sync operation has been canceled. |
| ` boolean` | ` https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter#onUnsyncableAccount()() ` Allows to defer syncing until all accounts are properly set up. |

### 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*.

## Constants

### LOG_SYNC_DETAILS

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

```
public static final int LOG_SYNC_DETAILS
```

<br />

**This constant was deprecated in API level 15.**   

Private constant. May go away in the next release.

Kernel event log tag. Also listed in data/etc/event-log-tags.

<br />

Constant Value: 2743 (0x00000ab7)

## Public constructors

### AbstractThreadedSyncAdapter

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

```
public AbstractThreadedSyncAdapter (Context context, 
                boolean autoInitialize)
```

Creates an `https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter`.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: the `https://developer.android.com/reference/android/content/Context` that this is running within. <br /> |
| `autoInitialize` | `boolean`: if true then sync requests that have `https://developer.android.com/reference/android/content/ContentResolver#SYNC_EXTRAS_INITIALIZE` set will be internally handled by `https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter` by calling `https://developer.android.com/reference/android/content/ContentResolver#setIsSyncable(android.accounts.Account,%20java.lang.String,%20int)` with 1 if it is currently set to \<0. <br /> |

### AbstractThreadedSyncAdapter

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

```
public AbstractThreadedSyncAdapter (Context context, 
                boolean autoInitialize, 
                boolean allowParallelSyncs)
```

Creates an `https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter`.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: the `https://developer.android.com/reference/android/content/Context` that this is running within. <br /> |
| `autoInitialize` | `boolean`: if true then sync requests that have `https://developer.android.com/reference/android/content/ContentResolver#SYNC_EXTRAS_INITIALIZE` set will be internally handled by `https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter` by calling `https://developer.android.com/reference/android/content/ContentResolver#setIsSyncable(android.accounts.Account,%20java.lang.String,%20int)` with 1 if it is currently set to \<0. <br /> |
| `allowParallelSyncs` | `boolean`: if true then allow syncs for different accounts to run at the same time, each in their own thread. This must be consistent with the setting in the SyncAdapter's configuration file. <br /> |

## Public methods

### getContext

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

```
public Context getContext ()
```

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/content/Context` | <br /> |

### getSyncAdapterBinder

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

```
public final IBinder getSyncAdapterBinder ()
```

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/IBinder` | a reference to the IBinder of the SyncAdapter service. <br /> |

### onPerformSync

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

```
public abstract void onPerformSync (Account account, 
                Bundle extras, 
                String authority, 
                ContentProviderClient provider, 
                SyncResult syncResult)
```

Perform a sync for this account. SyncAdapter-specific parameters may be specified in extras, which is guaranteed to not be null. Invocations of this method are guaranteed to be serialized.

<br />

| Parameters ||
|---|---|
| `account` | `Account`: the account that should be synced <br /> |
| `extras` | `Bundle`: SyncAdapter-specific parameters <br /> |
| `authority` | `String`: the authority of this sync request <br /> |
| `provider` | `ContentProviderClient`: a ContentProviderClient that points to the ContentProvider for this authority <br /> |
| `syncResult` | `SyncResult`: SyncAdapter-specific parameters <br /> |

### onSecurityException

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

```
public void onSecurityException (Account account, 
                Bundle extras, 
                String authority, 
                SyncResult syncResult)
```

Report that there was a security exception when opening the content provider prior to calling `https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter#onPerformSync(android.accounts.Account,%20android.os.Bundle,%20java.lang.String,%20android.content.ContentProviderClient,%20android.content.SyncResult)`. This will be treated as a sync database failure.

<br />

| Parameters ||
|---|---|
| `account` | `Account`: the account that attempted to sync <br /> |
| `extras` | `Bundle`: SyncAdapter-specific parameters <br /> |
| `authority` | `String`: the authority of the failed sync request <br /> |
| `syncResult` | `SyncResult`: SyncAdapter-specific parameters <br /> |

### onSyncCanceled

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

```
public void onSyncCanceled (Thread thread)
```

Indicates that a sync operation has been canceled. This will be invoked on a separate thread than the sync thread and so you must consider the multi-threaded implications of the work that you do in this method.

This will only be invoked when the SyncAdapter indicates that it does support parallel syncs.

<br />

| Parameters ||
|---|---|
| `thread` | `Thread`: the Thread of the sync that is to be canceled. <br /> |

### onSyncCanceled

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

```
public void onSyncCanceled ()
```

Indicates that a sync operation has been canceled. This will be invoked on a separate thread than the sync thread and so you must consider the multi-threaded implications of the work that you do in this method.

This will only be invoked when the SyncAdapter indicates that it doesn't support parallel syncs.

<br />

### onUnsyncableAccount

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

```
public boolean onUnsyncableAccount ()
```

Allows to defer syncing until all accounts are properly set up.

Called when a account / authority pair

- that can be handled by this adapter
- `https://developer.android.com/reference/android/content/ContentResolver#requestSync(android.content.SyncRequest)`
- and the account/provider `https://developer.android.com/reference/android/content/ContentResolver#getIsSyncable(android.accounts.Account,%20java.lang.String)`.

This might be called on a different service connection as `https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter#onPerformSync(android.accounts.Account,%20android.os.Bundle,%20java.lang.String,%20android.content.ContentProviderClient,%20android.content.SyncResult)`.

The system expects this method to immediately return. If the call stalls the system behaves as if this method returned `true`. If it is required to perform a longer task (such as interacting with the user), return `false` and proceed in a difference context, such as an `https://developer.android.com/reference/android/app/Activity`, or foreground service. The sync can then be rescheduled once the account becomes syncable.   

This method must be called from the main thread of your app.

<br />

| Returns ||
|---|---|
| `boolean` | If `false` syncing is deferred. Returns `true` by default, i.e. by default syncing starts immediately. <br /> |