0

I am using a ScheduledThreadPoolExecutor in my application where I need consistent, precise timing with a delay of 2 seconds.

When would AlarmManager be preferred and from the API docs, it seems like it'd be more power efficient. Is one "meant" more to be used as a background processor or foreground? Would there be any hardware limitations, ie. If I use AlarmManager, would I be able to access the camera for instance as long as I requested that permission? Or, is that resource out of scope in this context?

JobScheduler is out of the question for me because that appears to require a 15 minute interval at a minimum.

Handler only appears to function when the app is in the foreground.

Are those my only options?

Walter
  • 1,290
  • 2
  • 21
  • 46
  • What time interval are you looking to fire the alarm manager at? It also has a limit, either 1minute or 15minutes as well – Amin Mar 19 '21 at 03:28
  • I'm looking for a delay around 2 seconds presently. After testing more, I might find that I want to do 5, 10, or 30 (seconds). But whatever that # is, I want it to be consistent. – Walter Mar 19 '21 at 10:41
  • To be honest at that rate, you might just want to go for a constantly open foreground service (you can try background service but it may get killed on some android oems), rather than firing an alarmmanager so often. The AlarmManager won't fire that often anyways, they also have interval limits on that implementation – Amin Mar 19 '21 at 15:40
  • What do time lapse implementations typically use? – Walter Mar 19 '21 at 16:45
  • Well they usually do foreground camera, and [here's](https://stackoverflow.com/questions/36176085/how-to-implement-slowmotion-and-timelapse-video-recording-using-camera-api) a helpful SO link that shows the Camera2 API actually has a timelapse mode built in, and [a github example project](https://github.com/saki4510t/TimeLapseRecordingSample) – Amin Mar 19 '21 at 17:13
  • Okay, so, if I do foreground, what happens if the app goes to the background, I turn off the screen, etc.? I thought that is why I wanted to background everything (this is my first dip into Android). – Walter Mar 19 '21 at 17:19
  • https://developer.android.com/guide/components/foreground-services#types, foreground service like i mentioned earlier. You can't have a completely invisible background camera running, that's restricted for security reasons – Amin Mar 19 '21 at 17:23
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/230143/discussion-between-walter-and-amin). – Walter Mar 19 '21 at 19:38

0 Answers0