Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Android decoupling came to bite me again. It appears that both apps needed to also have a <code>sync_adapter.xml</code> like:</p> <pre><code>&lt;!-- The attributes in this XML file provide configuration information for the SyncAdapter. --&gt; &lt;sync-adapter xmlns:android="http://schemas.android.com/apk/res/android" android:contentAuthority="mypackage" android:accountType="mypackage.account" android:supportsUploading="true" android:userVisible="true" android:allowParallelSyncs="false" android:isAlwaysSyncable="true"/&gt; </code></pre> <p>and connect that to the sync service in the <code>AndroidManifest.xml</code>:</p> <pre><code>&lt;!-- Data sync service that provides the SyncAdapter to the SyncManager framework. The SyncAdapter is used to maintain that the set of data on the device is a subset of the data on the server --&gt; &lt;service android:exported="true" android:name=".data.sync.SyncService" tools:ignore="ExportedService"&gt; &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/sync_adapter"/&gt; &lt;/service&gt; </code></pre> <p>For completeness, my <code>Service</code> is implemented as follows:</p> <pre><code>/** * Service that provides sync functionality to the SyncManager through the {@link SyncAdapter}. */ public class SyncService extends Service { @Override public void onCreate() { synchronized (_sync_adapter_lock) { if (_sync_adapter == null) _sync_adapter = new SyncAdapter(getApplicationContext(), false); } } @Override public IBinder onBind(Intent intent) { return _sync_adapter.getSyncAdapterBinder(); } private static final Object _sync_adapter_lock = new Object(); private static SyncAdapter _sync_adapter = null; } </code></pre> <p>and the <code>SyncAdapter</code>:</p> <pre><code>/** * Sync adapter for KeepandShare data. */ public class SyncAdapter extends AbstractThreadedSyncAdapter { public SyncAdapter(Context context, boolean should_auto_initialize) { super(context, should_auto_initialize); //noinspection ConstantConditions,PointlessBooleanExpression if (!BuildConfig.DEBUG) { Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable throwable) { Log.e("Uncaught sync exception, suppressing UI in release build.", throwable); } }); } } @Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult sync_result) { // TODO: implement sync } } </code></pre> <p>Even though I'm not actually syncing any data (the apps are not even linked to any server right now), the Android framework appears to be using the settings of the <code>SyncAdapter</code> to figure out which account authenticator respond to the add account request.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload