Search code examples
androidalarmmanagerandroid-alarms

How to schedule Alarm without AlarmManager API


i want to schedule an alarm without the AlarmManager API, because this doesn't work on my samsung device ( samsung smart manager cancel alarm), but i don't know how i can do this ?


Solution

  • If this is truly an alarm clock sort of app, there are alarm clock methods on AlarmManager that should be reliable. They will have side effects, such as bits of system UI that you can't control.

    However, any other sort of on-device time-based scheduled work will be unreliable, as too many developers wasted too much battery on this sort of thing. Google and device manufacturers, based upon user complaints regarding battery life, have taken steps to limit the damage that AlarmManager can cause:

    • Android 6.0+ has Doze mode and app standby
    • SONY has their STAMINA mode
    • Samsung has their equivalent
    • And so on

    Google seems to be emphasizing JobScheduler (or GcmNetworkManager, if you are using Play Services) as the preferred approach for periodic work, and you are certainly welcome to use it. However, it is only available on Android 5.0+. And, as with some aspects of AlarmManager, JobScheduler is inexact — your events will not fire at exactly the requested time, but rather at some nearby time, to help try to minimize the number of times we have to wake up the device out of a sleep mode. And JobScheduler is also affected by Doze mode and app standby on Android 6.0+.