Alarm Manager

 

Whatever we code in android are made to be executed at that moment. But what if we want to trigger an event or task or an action in a time in future; may be after 15 mins , and hour or a day. To help ease this process the class AlarmManager is provided to us.

Lets get started and learn more about alarms.

Alarm Manager

 

Alarms:

What is an alarm? Alarms are the mechanism to schedule an intent in specific time in future.

Why do we need an alarm? We need an alarm to perform an action in future even if the application is not running.

Have we ever noticed that even if we exit the bluetooth connection application; it’s visibility timeout will be disabled at the mentioned time? Another obvious example is our clock.

Alarms can we very useful if you want to develop an app that allows certain notifications or triggers in future and perform respective functions.

Alarm Manager:

Quickly we’ll dive into the basics of alarm creation and take a look at the APIs provided for alarms.

  • Get an access to system’s alarm services:
    • getSystemService(ALARM_SERVICE)
  • Creating alarms
    • one-shot alarm
      • void set(int type, long triggerAtMillis, PendingIntent operation)
    • repeating alarm
      • void setRepeating(int type, long triggerAtMillis, long intervalMillis, PendingIntent operation)
    • repeating alarm in exact trigger time
      • void setInexactRepeating(int type, long triggerAtMillis, long intervalMillis, PendingIntent operation)

Continue reading