Android Alarm

| Page Views: 388

Android Alarm Tutorial and Examples.

Top Android Alarm Examples

Let's look at some examples.

AlarmManager is a class that allows us create alarms. Alarms allow our apps to schedule specific codes to be executed at certain times in the future.

public class AlarmManager extends Object{}

It's better and more efficient to use AlarmManager class to create alarms for scheduling than using something like a timer.

AlarmManager provides to us the access to system alarm services, so it's not like we are going to invent our scheduling algorithms.

AlarmManager is mostly used together with BroadcastReceivers. Here's how it works:

  • First Alarm goes off or rings.
  • The system broadcasts an intent. This is the intent which had been registered for it.
  • This automatically starts the target application in case it's not already running.
  • If the device sleeps, the alarms that are already registered get retained.
  • If the alarm goes off while the device is sleeping, then the device is woken up. This is optional.
  • If the user turns the device off or reboots it, then the alarms are cleared.

How to make a repeating alarm with cancellation. The alarm can ring even if the activity is not started.

One of those mobile-like software applications is the Alarm. Or any app that can schedule something to happen in the future. This is even more important in mobile devices than in desktop applications.

Because we never leave or power off our mobile devices. They are our personal assistants. So we use them in more personal ways than we would ever do with desktop applications.

So Android provides us a rich class called AlarmManager. A class that allows us access system services. The class is obviously public and derives from java.lang.Object.

Best Regards, Oclemy.

How do You Feel after reading this?

According to scientists, we humans have 8 primary innate emotions: joy, acceptance, fear, surprise, sadness, disgust, anger, and anticipation. Feel free to tell us how you feel about this article using these emotes or via the comment section.

About Me.

After completing his Software Engineering bachelors program, Oclemy(Clement Ochieng) these days is a man of two lives. At day he works for a startup in Nairobi, Kenya. At night he works tirelessly on building ProgrammingWizards TV, a tv channel for student coders and this website to help share the source code. In between he practices Meditation and Self actualization to help him keep balance. He also likes going for long solo walks to connect more with nature.


What do You Think

Previous Post Next Post