0

I have a SyncAdapter that periodically pull a request to the Server. I init the sync with addPeriodicSync() in my main Activity and all works fine. But i'd like to prevent the synchadapter to trigger onPerformSynch while the app is in background. I know that exist removePeriodicSync() but i don't know when to call it. Should i call it every time that an Activity goes in Pause? ( in onPause() method? ). Or there is a better method to know when an activity goes to background and when come to foreground? Anyway, calling addPeriodicSync() and removePeriodicSync() so frequently can cause any problem? Thanks in advance.

Nameless
  • 259
  • 2
  • 4
  • 15
  • The *point* of `SyncAdapter` is to be run in the background. – CommonsWare Feb 21 '14 at 15:09
  • Yes, you're right. But how can i reach the same result without a synchAdapter? I need to do handle either PUSH and PULL from a server ( it is a requirement). So i decided to handle both inside the onPerformSynch method of SynchAdapter. The only thing that change in the two cases is the way with i request the synchronization. (In the case of PUSH the request it's done inside the GCM service). Furthermore, if i use a service always in background for GCM PUSHES and one other ALWAYS in background that do a request every 30 seconds, is it not a big overhead? – Nameless Feb 21 '14 at 15:30
  • "But how can i reach the same result without a synchAdapter?" -- by programming. You do not need `SyncAdapter` to perform HTTP operations to and from a server. "one other ALWAYS in background that do a request every 30 seconds" -- doing network I/O every 30 seconds will be "big overhead" whether you force `SyncAdapter` to do the work every 30 seconds or you do it some other way every 30 seconds. – CommonsWare Feb 21 '14 at 15:34

0 Answers0