【发布时间】:2016-01-08 19:56:51
【问题描述】:
尝试为我的内容提供商设置同步适配器/服务。内容提供者工作正常,能够毫无问题地存储数据。
我有一个向我的内容解析器注册的内容观察器,并且在数据更改后调用 onChange 方法。
但是,在我调用observer.onChange 之后,日志中没有出现任何内容。在observer.onChange 中,我调用了contentResolver.requestSync,但未调用同步适配器中的onPerformSync 方法。
想法?
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"/>
身份验证器.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"/>
观察者 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);
}
清单:
<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>
【问题讨论】:
-
在 onChange 函数中放置一个调试点,首先确保正在调用。如果是,我们可以向前看。一个常见的错误
标签: android android-syncadapter