Android

Android Alarm Manger Tutorial – Scheduling your task using Android AlarmManager

Android AlarmManger Tutorial | Android Alarm Manger Tutorial | Android AlarmManger | Android Alarm

android.app.AlarmManager

 

This class provides access to the system alarm services. These allow you to schedule your application to be run at some point in the future. When an alarm goes off, the intent that had been registered for it is broadcast by the system, automatically starting the target application if it is not already running. Registered alarms are retained while the device is asleep (and can optionally wake the device up if they go off during that time), but will be cleared if it is turned off and rebooted.

 

Note: The Alarm Manager is intended for cases where you want to have your application code run at a specific time, even if your application is not currently running. For normal timing operations (ticks, timeouts, etc) it is easier and much more efficient to use Handler.

 

For more see the developer doc, https://developer.android.com/reference/android/app/AlarmManager.html/

Add this below dependencies on your app build.gradle

Add this below code in your android manifest file…….. Before </application> tag

 

This is our Main Activity Class

In this class we have used two button one is to start our alarm and another is for to cancel our alarm

 

 

This is our Alarm Receiver class

This will be call when we start our alarm and then it will invoke our service class to start the ringtone……….

 

This is our app main layout file

 

 

This is our service class

We manipulate our alarm ringtone using this service class. we start ringtone when alarm is on. when we click on cancel button it stops the service. So it automatically stops the ringtone. As ringtone play when service is alive. Service dead so alarm ringtone is dead………

 

What will you learn from this…………………

  1. You learn to implement alarm on your android project
  2. You can start and cancel an alarm
  3. You learn to implement broadcast receiver class and service class…

Leave a Reply

Your email address will not be published.

3 × 1 =