title: Do I need to stop periodic GcmTaskServices?
body: <p>I'm trying to implement a <code>PeriodicTask</code> with the <code>GcmNetworkManager</code> API (existing since <code>Google Play Services 7.5</code>).</p>
  
  <p>My task is scheduled as soon as my app starts and will check the content of a <code>Queue</code> of objects in order to send them as batches to my server.
  If the queue is empty, the method <code>onRunTask()</code> will do pretty much nothing (it will check the queue and <code>return GcmNetworkManager.RESULT_SUCCESS</code>).</p>
  
  <hr>
  
  <p>I have put some logs in the implementation and noticed that the <code>PeriodicTask</code> keeps running forever, even after my app is in background or removed from memory.</p>
  
  <p>This made me worry about my users' battery. Even though I won't perform any heavy task or HTTP request, the process is started periodically without real need.</p>
  
  <p>At first, I thought <code>GcmNetworkManager</code> would be smart to exponentially back-off my <code>Task</code> until it stopped (or maybe I'm doing something wrong that prevents that), but, as my logs showed, that did not happen.</p>
  
  <p>Afterwards, I have tried using <code>cancelTask()</code> and <code>cancelAll()</code> but those do not work if called from within the <code>Task</code>'s <code>onRunTask()</code> method itself. Even calling <code>stopSelf()</code> is not a good idea since <code>GcmNetworkManager</code> is the one responsible for the <code>Service</code> lifecycle so I do not want to get in the way.</p>
  
  <p>The difficulty of actually finishing the task made me think if that is the right approach (maybe I should just let the <code>Task</code> live forever?).</p>
  
  <hr>
  
  <p>How can I use <code>PeriodicTask</code> properly while not draining the user's battery?</p>