Android SyncAdapter: retry

你离开我真会死。 提交于 2019-12-25 03:32:49

问题


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++;

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());

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.

How can I do it?


回答1:


Documentation say's: (http://developer.android.com/reference/android/content/ContentResolver.html#addPeriodicSync(android.accounts.Account, java.lang.String, android.os.Bundle, long))

Periodic syncs are not allowed to have any of 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 set to true. If any are supplied then an IllegalArgumentException will be thrown.

Maybe that's the problem. Try remove this params - may work. Write if it helps.

Or You forgot permissions:

<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" />


来源:https://stackoverflow.com/questions/15810659/android-syncadapter-retry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!