Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set an exact repeating alarm on API 19 (kitkat)?

Starting from API 19, setRepeating() works the same way as setInexactRepeating(). What's the new way of setting an exact repeating alarm?

I.e. What's the API 19 version of the good old setRepeating()? Could you please provide an example for setting an alarm at 7:30 every morning (repeating daily) on KitKat?

like image 481
user1032613 Avatar asked Jun 19 '14 04:06

user1032613


People also ask

What is an exact alarm?

What is this permission? The new exact alarm permission ( SCHEDULE_EXACT_ALARM ) was created to save system resources. Alarms that must be executed in an exact time may be triggered when the phone is on power-saving mode or Doze, making the app consumes more battery than it should.

How alarm Manager works?

The Alarm Manager holds a CPU wake lock as long as the alarm receiver's onReceive() method is executing. This guarantees that the phone will not sleep until you have finished handling the broadcast. Once onReceive() returns, the Alarm Manager releases this wake lock.

How to use alarm Manager in Android?

This example demonstrates how do I use AlarmManager in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.


1 Answers

It doesn't exist, unfortunately. From the documentation:

Note: as of API 19, all repeating alarms are inexact. If your application needs precise delivery times then it must use one-time exact alarms, rescheduling each time as described above. Legacy applications whose targetSdkVersion is earlier than API 19 will continue to have all of their alarms, including repeating alarms, treated as exact.

In short, if you need exact repeating alams, you can create an alarm with setExact(), but you'll need to handle the "repeating" part manually.

like image 164
matiash Avatar answered Nov 15 '22 21:11

matiash