0% found this document useful (0 votes)
36 views1 page

Alarmmanager Broadcast Receiver Service

An AlarmManager is used to trigger code at specific times independently of an app's lifecycle. It gets the AlarmManager instance and passes a PendingIntent to schedule code execution. There are different alarm types like inexact repeating and exact alarms. AlarmManagers can consume battery if not handled properly and may not repeat as frequently in low power modes.

Uploaded by

Nazia Tabassum
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views1 page

Alarmmanager Broadcast Receiver Service

An AlarmManager is used to trigger code at specific times independently of an app's lifecycle. It gets the AlarmManager instance and passes a PendingIntent to schedule code execution. There are different alarm types like inexact repeating and exact alarms. AlarmManagers can consume battery if not handled properly and may not repeat as frequently in low power modes.

Uploaded by

Nazia Tabassum
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

AlarmManager Broadcast Receiver Service

An AlarmManager is used to trigger some code at a specific time. It uses


the Android SDK’s alarm service and runs independently of the
application’s lifecycle.
To start an Alarm Manager you need to first get the instance from the
System. Then pass the PendingIntent which would get executed at a future
time that you specify.

AlarmManager manager = (AlarmManager)


getSystemService(Context.ALARM_SERVICE);

Intent alarmIntent = new Intent(context,


MyAlarmReceiver.class);
PendingIntent pendingIntent =
PendingIntent.getBroadcast(context, 0, alarmIntent, 0);
int interval = 8000;
manager.setInexactRepeating(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis(), interval, pendingIntent);

There are different types of Alarm Manager that can be invoked:

 setInExactAndRepeating – This doesn’t trigger the alarm at the exact


time.
 setExact – Setting an alarm manager using this ensures that the OS
triggers the alarm at almost the exact time.
 setExactAndAllowWhileIdle – This method came up with Android M.
These types of alarms are allowed to get executed even in low power
modes.

You need to be careful while using the Alarm Manager since they can
consume battery if not handled properly.
Normally, an alarm manager cannot repeat before a minute. Also in low
power mode, the duration can increase to up to 15 minutes.
Broadcast Receivers listen to system-wide and application events.
In order to trigger a Broadcast Receiver when the system is rebooted, you
need to call ACTION_BOOT_COMPLETED.

You might also like