title: Android periodic sync
body: <p>I have a <code>SyncAdapter</code> that needs to be synced every midnight. I'm executing periodic syncs using <code>ContentResolver.addPeriodicSync</code>, but I don't know how to trigger it at midnight. </p>
  
  <p>I've thought on a couple of options but none of them seem quite right:</p>
  
  <ol>
  <li>Setup an alarm (with <code>AlarmManager</code>) that triggers at midnight, fire a <code>Broadcast</code> with a sync intent and register/unregister receivers in every <code>Activity</code>.</li>
  <li>Similar as 1., but using a <code>Service</code>. The service is fired on start up and runs indefinitely.</li>
  </ol>
  
  <p>Any ideas on how to do this properly?</p>