user1459641
user1459641

Reputation: 458

Android syncadapter onPerformSync not called

Trying to set up a sync adapter/service for my content provider. The content provider works fine, able to store data with no issues.

I have a content observer that is registered with my content resolver and the onChange method is invoked after a data change.

But, nothing is coming up in the logs after I call observer.onChange. In observer.onChange I make a call to contentResolver.requestSync but the onPerformSync method in my sync adapter is not invoked.

Ideas?

syncadapter.xml

<sync-adapter
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:contentAuthority="....contentproviderexample.provider"
    android:accountType="....contentproviderexample"
    android:userVisible="false"
    android:supportsUploading="false"
    android:allowParallelSyncs="false"
    android:isAlwaysSyncable="true"/>

authenticator.xml

<account-authenticator
    android:label="@string/app_name"
    android:smallIcon="@mipmap/ic_launcher"
    android:icon="@mipmap/ic_launcher"
    android:accountType="....contentproviderexample"
    xmlns:android="http://schemas.android.com/apk/res/android"/>

Observer onChange:

@Override
        public void onChange(boolean selfChange, Uri uri) {
            Log.d(PERSON_OBSERVER_TAG, "onChange:  Calling requestSync");
            contentResolver.requestSync(newAccount, PersonContract.CONTENT_AUTHORITY, Bundle.EMPTY);
        }

manifest:

<service android:name=".datasync.AuthenticatorService">
            <intent-filter>
                <action android:name="android.accounts.AccountAuthenticator"></action>
            </intent-filter>
            <meta-data
                android:name="android.accounts.AccountAuthenticator"
                android:resource="@xml/authenticator"/>
        </service>

        <service android:name=".datasync.SyncService"
            android:exported="true"
            android:process=":sync">

            <intent-filter>
                <action android:name="android.content.SyncAdapter"/>
            </intent-filter>
            <meta-data
                android:name="android.content.SyncAdapter"
                android:resource="@xml/syncadapter">

            </meta-data>
        </service>

Upvotes: 2

Views: 3812

Answers (2)

Vasudev
Vasudev

Reputation: 1996

As SyncService runs in its own process, which is different from your app's, as defined by android:process=":sync", the logs do not appear. Though the SyncAdapter is being run.

To see logs instead of 'show only selected application' choose 'no filters' in logcat.

You don't have to remove android:process=":sync".

Upvotes: 7

user1459641
user1459641

Reputation: 458

By removing the following, everything is working fine:

android:process=":sync"

Removed that from the SyncService configuration and the onPerformSync method is called after and update to the the content provider.

thanks

Upvotes: 6

Related Questions