How to create an alarm using AlarmManager

Updated 6 January 2018

Save

What’s the AlarmManager used for?

The AlarmManager is used to schedule events or services at either a set time or a set interval. It’s Android’s “version” of the cron. In this case, we’re going to set an alarm for five seconds after the app is launched.

What we’re going to build

In order to use it, we’re going to create an alarm which will be called after a time interval and we will perform a task using it.

Let’s have a look at the steps to create an alarm

  1. Create an IntentService which will execute some task and will be triggered by a BroadcastReceiver. The example below provides you the idea of it.
  2. Create a BroadcastReceiver which will monitor the alarm triggering and execute the IntentService for you according to it. Look at the below given example
  3. Now we will schedule the alarm. The minimum time interval for the alarm is 60 seconds because below this time interval the alarm will consume a lot of battery.
  4. And to cancel the alarm.

     

This is all you need to do to create an alarm and perform your task. It will be triggered after the time period specified automatically.

Thank you very much. This is Vedesh Kumar signing off.

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home