title: Running a repeating task in background on a real time application
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5773998/running-a-repeating-task-in-background-on-a-real-time-application">Running a repeating task in background on a real time application</a>  </p>
  </blockquote>
  
  
  
  <p>Hi! I'm writing an application which is continuously listening and checking the sensors (almost all available) and saving that data into the database in the device. </p>
  
  <p>I need to make some calculations every X second with that data and throw a new event if the calculations check says so. 
  I'm thinking about requesting to have the device plugged in while using the application (regarding battery drain).</p>
  
  <p>What's the best approach for the task that needs to make the calculations and throw the event? Timer? Threads? AsynkTask? AlarmManager? Another approach?</p>
  
  <p>I want to keep getting sensors data and saving them to the database despite if the application is not on foreground...it should save the values as long as the application is not stopped by the user. 
  One option for that is wake locks (PARTIAL_WAKE_LOCK, which keeps CPU running).</p>
  
  <p>I'm wondering how an application checking if you are on the correct way while running (imagine tha moving a few meter of your path would need to be advised) would be developed despite it is not exactly my case.
  I'd like to hear different opinions.
  Thanks in advance! Guillermo.</p>