问题描述
我使用的是 AbstractThreadedSyncAdapter
来的一些数据和我的服务器同步。我使用 SyncResult
来表示,如果有是一个错误在执行同步:
I'm using an AbstractThreadedSyncAdapter
to synchronize some data with my server. I'm using SyncResult
to indicate if there's been an error while performing the synchronization:
syncResult.stats.numParseExceptions++;
我初始化SyncAdapter是这样的:
I initialize the SyncAdapter like this:
Bundle params = new Bundle();
params.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, false);
params.putBoolean(ContentResolver.SYNC_EXTRAS_DO_NOT_RETRY, false);
params.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);
ContentResolver.addPeriodicSync(account, CONTENT, params, 3600);
ContentResolver.setSyncAutomatically(account, CONTENT, true);
ContentResolver.requestSync(account, CONTENT, new Bundle());
如果同步失败,我希望它在5分钟后重试(周期性同步时间为1小时)。我想,我不得不使用 syncResult.delayUntil
,但同步不重试。
If the synchronization fails I want it to retry after 5 minutes (periodic sync time is 1 hour). I thought that I had to use syncResult.delayUntil
, but the synchronization isn't retried.
我该怎么办呢?
推荐答案
文档说的:(http://developer.android.com/reference/android/content/ContentResolver.html#addPeriodicSync(android.accounts.Account, java.lang.String中,android.os.Bundle,长))
Documentation say's: (http://developer.android.com/reference/android/content/ContentResolver.html#addPeriodicSync(android.accounts.Account, java.lang.String, android.os.Bundle, long))
周期性同步不允许有任何SYNC_EXTRAS_DO_NOT_RETRY,SYNC_EXTRAS_IGNORE_BACKOFF,SYNC_EXTRAS_IGNORE_SETTINGS,SYNC_EXTRAS_INITIALIZE,SYNC_EXTRAS_FORCE,SYNC_EXTRAS_EXPEDITED的,SYNC_EXTRAS_MANUAL设置为true。如果有任何供给那么将抛出IllegalArgumentException。
也许这就是问题所在。尝试删除该PARAMS - 可能工作。写如果它帮助。
Maybe that's the problem. Try remove this params - may work. Write if it helps.
或者你忘了权限:
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
这篇关于Android的SyncAdapter:重试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!