Partager via


AbstractThreadedSyncAdapter Class

Definition

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

[Android.Runtime.Register("android/content/AbstractThreadedSyncAdapter", DoNotGenerateAcw=true)]
public abstract class AbstractThreadedSyncAdapter : Java.Lang.Object
[<Android.Runtime.Register("android/content/AbstractThreadedSyncAdapter", DoNotGenerateAcw=true)>]
type AbstractThreadedSyncAdapter = class
    inherit Object
Inheritance
AbstractThreadedSyncAdapter
Attributes

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 #onPerformSync 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. <strong>Either your code in #onPerformSync(Account, Bundle, String, ContentProviderClient, SyncResult) must check Thread#interrupted(), or you you must override one of #onSyncCanceled(Thread)/#onSyncCanceled()</strong> (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 #getSyncAdapterBinder() in the service's 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

&lt;intent-filter&gt;
                &lt;action android:name="android.content.SyncAdapter" /&gt;
              &lt;/intent-filter&gt;
              &lt;meta-data android:name="android.content.SyncAdapter"
                        android:resource="@xml/syncadapter" /&gt;

The android:resource attribute must point to a resource that looks like:

&lt;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"
            /&gt;

<ul> <li>The android:contentAuthority and android:accountType attributes indicate which content authority and for which account types this sync adapter serves. <li>android:userVisible defaults to true and controls whether or not this sync adapter shows up in the Sync Settings screen. <li>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(android.net.Uri, android.database.ContentObserver, boolean) with syncToNetwork set to true. <li>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. <li>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. <li>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. </ul>

Java documentation for android.content.AbstractThreadedSyncAdapter.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

AbstractThreadedSyncAdapter(Context, Boolean, Boolean)

Creates an AbstractThreadedSyncAdapter.

AbstractThreadedSyncAdapter(Context, Boolean)

Creates an AbstractThreadedSyncAdapter.

AbstractThreadedSyncAdapter(IntPtr, JniHandleOwnership)

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

Fields

LogSyncDetails
Obsolete.

Kernel event log tag.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Context
Handle

The handle to the underlying Android instance.

(Inherited from Object)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
SyncAdapterBinder
ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Methods

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

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

(Inherited from Object)
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
JavaFinalize()

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

(Inherited from Object)
Notify()

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

(Inherited from Object)
NotifyAll()

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

(Inherited from Object)
OnPerformSync(Account, Bundle, String, ContentProviderClient, SyncResult)

Perform a sync for this account.

OnSecurityException(Account, Bundle, String, SyncResult)

Report that there was a security exception when opening the content provider prior to calling #onPerformSync.

OnSyncCanceled()

Indicates that a sync operation has been canceled.

OnSyncCanceled(Thread)

Indicates that a sync operation has been canceled.

OnUnsyncableAccount()

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

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

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

(Inherited from Object)
Wait(Int64)

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

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to