title: Android background service, best way to schedule task every 10 seconds if device is awake
body: <p><strong>Background</strong></p>
  
  <p>I am writing an Android Service that </p>
  
  <ul>
  <li>always running</li>
  <li>repeatedly perform a simple task if device is awake</li>
  </ul>
  
  <p>I am able to make the service start on device boot.
  But I am <strong>confused about task scheduling</strong>.</p>
  
  <p><strong>Creteria:</strong> I want to schedule the task such that it:</p>
  
  <ul>
  <li>run on roughly every 10 seconds if device is awake/screen is on</li>
  <li>can be cancelled</li>
  <li>consume minimum system resource (CPU &amp; Memory) </li>
  <li><strong>the device should not and need not be waked to run the task</strong></li>
  </ul>
  
  <p>I found there are many ways to schedule tasks: Thread, AsyncTask, Runnable with Handler , AlarmManager, Timer, JobScheduler. </p>
  
  <p>I don't know which one to pick.
  (AFAIK period of AlarmManager is limited to at least 60s in modern Android version)</p>
  
  <p><strong>2 Questions:</strong></p>
  
  <ul>
  <li><em>Which method should I use?</em> </li>
  <li><em>Should I schedule to run the service and the service perform the task once?</em>
  <em>Or should I have the service scheduling the task?</em></li>
  </ul>
  
  <p>I am totally new to android development. Thank you.</p>