Android Guides | Samples

Android.Content.AbstractThreadedSyncAdapter Class

An abstract implementation of a SyncAdapter that spawns a thread to invoke a sync operation.

See Also: AbstractThreadedSyncAdapter

Syntax

[Android.Runtime.Register("android/content/AbstractThreadedSyncAdapter", DoNotGenerateAcw=true)]
public abstract class AbstractThreadedSyncAdapter : Object

Remarks

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 AbstractThreadedSyncAdapter.OnPerformSync(Account,Bundle,Bundle,Bundle,Bundle) 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 30 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 ContentResolver.CancelSync(Account,String) or ContentResolver.CancelSync(SyncRequest).

A sync is cancelled by issuing a Thread.Interrupt on the syncing thread. Either your code in AbstractThreadedSyncAdapter.OnPerformSync(Account,Bundle,Bundle,Bundle,Bundle) must check Thread.Interrupted, or you you must override one of AbstractThreadedSyncAdapter.OnSyncCanceled(Thread)/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 AbstractThreadedSyncAdapter.SyncAdapterBinder in the service's Service.OnBind(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

xml Example

   <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:

xml Example

 <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 ContentResolver.NotifyChange(Uri,ContentObserver,ContentObserver) 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 intialize 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.

[Android Documentation]

Requirements

Namespace: Android.Content
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 5

The members of Android.Content.AbstractThreadedSyncAdapter are listed below.

See Also: Object

Public Constructors

Protected Constructors

A constructor used when creating managed representations of JNI objects; called by the runtime.

Public Fields

const
LogSyncDetailsInt32 (2743). Kernel event log tag.

Public Properties

[read-only]
ContextContext.
[read-only]
SyncAdapterBinderIBinder.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

abstract
OnPerformSync(Account, Bundle, String, ContentProviderClient, SyncResult)
Perform a sync for this account.
OnSyncCanceled()
Indicates that a sync operation has been canceled.
OnSyncCanceled(Thread)
Indicates that a sync operation has been canceled.