title: SyncAdapter : Periodic Sync only when app in foreground
body: <p>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. </p>