title: Android Service doing work at timed intervals
body: <p>I am trying to create an Android Service that does work at every X seconds in the background.</p>
  
  <ul>
  <li>It needs to run "forever" until stopped by the user, so I guess it needs to be a foreground service with a notification, so it won't get killed</li>
  <li>The user needs to be able to stop and start the service, and only a single service should be running at the same time</li>
  <li>The service should do work (specifically call the Camera2 API, do some web upload etc.) every X seconds, but otherwise be idle.</li>
  <li>If possible (not a requirement), could the service continue running independently even if the UI crashes for some reason?</li>
  </ul>
  
  <p>Should I use a Service, IntentService, Bound service or something else? Can a Timer class somehow work in cooperation with this?</p>
  
  <p>As for the "doing work periodically" I considered just creating a new Thread on service start and make it sleep in between requests. But I guess that is bad practice and creates a lot of maintenance overhead and manual state tracking. Also, the Android APIs it needs to call, requires to be run on the main thread to work, so that will not work directly.</p>