Alarm


Alarm

We know how important is the Alarm utility in Android, and the best part is it can be incorporated with any other application as per the preference of the developers. As a developer when you are working with an alarm, the first thing you need to remember is the class to which the Alarm belongs to. In this case, it will be AlarmManager.

So, if you are looking to use the Alarm feature in your application you have to inherit the AlarmManager class. This class gives access to all the services associated with the system alarm. We can schedule the application to be run at a specific time in the future. As soon as the alarm triggers, the intent is broadcasted by the system, which in turn automatically triggers the target application. If the application is already running, then it doesn’t need to take any further action.

In case it is one of those alarms that is registered, then it will be retained even if the device is asleep. There is an option to wake up the device as well. However, the exception to this process is the alarm will be cleared if there is a reboot in progress or the device itself has been turned off. The AlarmManager controls the CPU wake lock, which ensures the phone doesn’t go to sleep mode until the broadcast is completed.

The following code demonstrates how AlarmManager can be used.

The activity needs to be coded and separate in a separate Java file. The probable output is shown below.

Image Not Found

Alarm

We know how important is the Alarm utility in Android, and the best part is it can be incorporated with any other application as per the preference of the developers. As a developer when you are working with an alarm, the first thing you need to remember is the class to which the Alarm belongs to. In this case, it will be AlarmManager.

So, if you are looking to use the Alarm feature in your application you have to inherit the AlarmManager class. This class gives access to all the services associated with the system alarm. We can schedule the application to be run at a specific time in the future. As soon as the alarm triggers, the intent is broadcasted by the system, which in turn automatically triggers the target application. If the application is already running, then it doesn’t need to take any further action.

In case it is one of those alarms that is registered, then it will be retained even if the device is asleep. There is an option to wake up the device as well. However, the exception to this process is the alarm will be cleared if there is a reboot in progress or the device itself has been turned off. The AlarmManager controls the CPU wake lock, which ensures the phone doesn’t go to sleep mode until the broadcast is completed.

The following code demonstrates how AlarmManager can be used.

The activity needs to be coded and separate in a separate Java file. The probable output is shown below.

Image Not Found