Android TutorialsNo Comments

default thumbnail
402 views.

Alarm is one of the best examples for BroadcastReceiver. This will be very useful to schedule an event after some amount of time even though the user has not opened the application. All we need to do is registering a broadcast. Android provides AlarmManager class which provides access to system alarm services. We The system will broadcast the Intent that had been registered using AlarmManager instance. This will happen when the alarm goes off. To know more about BroadcastReceiver concept visit this post.
We can schedule SMS to be sent or we can schedule a notification to the user using AlarmManager.
As stated in the AlarmManager javadoc, it holds a CPU wake lock as long as the alarm receiver’s onReceive() is executing. This means the device will no go to sleep state until the user finishes the broadcast. The AlarmManager will release the lock after the execution of onReceive() method.

set() method of the AlarmManager is used to register an Intent to be sent.
Syntax:
set (int type, long triggerAtMillis, PendingIntent operation)
here type is – One of ELAPSED_REALTIME, ELAPSED_REALTIME_WAKEUP, RTC or RTC_WAKEUP.
triggerAtMillis is – time in milliseconds that the alarm should go off.
operation is the Intent instance that will be sent when the alarm go off.

How to set repeated alarm in android am explaining you with below example.

activity_alarm_manager_example.xml

AlaramManagerExample.java

RingAlaram.java

Alaram.xml

 

Be the first to post a comment.

Add a comment