1

I am developing an android app that uses AlarmManager. The app has to be very accurate, but AlarmManager.setExact is available only from API 19 (Android Kitkat), and I have an old phone that its android version is 4 (API 16). I tried using a service, but it stops when I lock the phone. I need an alternative that works for APIs below 19. Does anyone have an idea?

  • Depending on your definition of "very accurate", nothing on Android is "very accurate" with respect to timing. – CommonsWare Jun 29 '17 at 17:46
  • @CommonsWare Very accurate means that the alarm will start in the second I want it to start – Paranoid Android Jun 29 '17 at 18:08
  • That won't happen with Doze mode and app standby on Android 6.0+. About the only thing that is fairly accurate (though perhaps not to the second) and reliable is `setAlarmClock()` on `AlarmManager`, and from the user's standpoint, that really should be reserved for alarm clock apps. – CommonsWare Jun 29 '17 at 18:10
  • @CommonsWare setAlarmClock is from android lollipop – Paranoid Android Jun 29 '17 at 18:29
  • Agreed. And, prior to Android 6.0, `set()`/`setExact()` were decent, though not necessarily down to the second, as there are lots of things going on in the device and it may take a moment to get around to forking a process for you and giving you control. – CommonsWare Jun 29 '17 at 18:32
  • @CommonsWare read my question again – Paranoid Android Jun 29 '17 at 18:49
  • You have not changed your question. Most likely, you should not be using Android for your project. For example, you might use a real-time OS (RTOS) on suitable hardware. – CommonsWare Jun 29 '17 at 19:03

1 Answers1

1

Just set(). Before API 19, set was an exact set. setExact was added when set was made inexact.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127