2

so i am running api version 7 with a custom syncAdapter service that makes calls to an API webservice to retrieve sync info. the issue with it is that this sync service starts itself every 10-30 seconds even though the sync has been successful and everything is up to date and working.

Is there anyway to define sort of a backoff period for it? is there anyway to resolve this issue? i see the syncresult variable but there isn't anything in it to indicate a successful sync or something like that.

Please help. Thanks.

DArkO
  • 15,880
  • 12
  • 60
  • 88

1 Answers1

2

You set the SyncResult variable in your onPerformSync method in your SyncAdapter. You'll see its one of the arguments to the onPerformSync method. There's a field there called delayUntil that you can use to tell it not to schedule another sync for a certain amount of time.

maxpower47
  • 1,666
  • 1
  • 10
  • 14
  • ye tnx for the tip but unfortunately i cant use it because its introduced in api 8. i am building for 7. maybe i can use it with reflection then just for the ones above 8. – DArkO Jun 21 '11 at 19:04
  • Ah. I haven't used it, but maybe the tooManyRetries field can help. According to the docs, this should keep it from being rescheduled. Take a look here too: http://stackoverflow.com/questions/5537581/when-syncadapter-runs-synchronization-on-android . Are you maybe inadvertently causing the syncs by calling notifyChange with the sync flag being true? – maxpower47 Jun 21 '11 at 19:07
  • ye i also saw this post. what i did is actually save a timestamp in shared preferences with the last sync time and not allow the sync if the period between the new and old is smaller than 15 mins. this seems to solve the service running constantly. it just stops after the first time it runs into the interval check from launching again. however i still allow it to be run with the manual sync flag to bypass that check. – DArkO Jun 21 '11 at 19:25
  • no need for reflection to use the delayUntil field, in AndroidManifest you should usually set minSdkVersion to the min. allowed api version (7 in your case), and targetSdkVersion to the max. allowed api version (usually the latest, i.e. 19 as of today), then you can use methods with if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {...} – marmor Mar 13 '14 at 10:36
  • 2
    To anybody else with this problem: just be aware that the documentation is a bit misleading on this - delayUntil is an absolute timestamp not a number of seconds. See the gotcha at the bottom of this post: http://www.geero.net/2014/03/adding-cloud-functionality-to-an-android-app/ – andygeers Mar 04 '15 at 13:46