title: Android: Send location data in background periodically (every 30 seconds) and ask server for new data
body: <p>Scenario:</p>
  
  <p>Post to server to get any new data in background every 30 seconds for long period i.e. 12 hours. Location data needs to be sent along with this.</p>
  
  <p>Current Implementation; </p>
  
  <p>Service Class;</p>
  
  <ol>
  <li>Location listener with interval of 30 seconds which sets the longitude &amp; latitude values to two local variables</li>
  <li>Alarm manager fires pending Intent every 30 seconds to a broadcast receiver.</li>
  <li>Broadcast receiver starts an IntentService with location variables in the extras.</li>
  <li>The IntentService http posts location and asks for any new data from server.</li>
  <li><p>IntentService send server response back to main service class via broadcast receiver.</p>
  
  <ul>
  <li>Service class starts_sticky to ensure restart by the OS.</li>
  </ul></li>
  </ol>
  
  <p>I have tried a few different variations;</p>
  
  <ol>
  <li><p>I've tried using a Handler and runnable to handle the timing mechanism for posting to the server however,  the postDelay time went from 2 minutes to 7 minutes when device is asleep.</p></li>
  <li><p>Also, tried firing IntentService directly from alarm manager but could not change PendingIntent extras with the most up-to-date location variables.</p></li>
  </ol>
  
  <p>Questions;</p>
  
  <ol>
  <li><p>Is the current implementation the way to go?</p></li>
  <li><p>Would going down google's GCM route be much more beneficial? </p></li>
  <li><p>How can you vigorously test the service class especially with respect to recovering from the OS killing it?</p></li>
  </ol>
  
  <p>Thanks in advance. </p>