Rigid AlarmManager

Context

Implementation

Affects

Efficiency,Energy Efficiency

Problem

With the use of AlarmManager it is possible that operations can be executed at a sepcific moment in the future. It is possible that several operations got executed. Every AlarmManager-triggered operation wakes up the phone, so the overall use of energy and CPU might be higher, then if bundled together.

AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

Intent intent = new Intent(context, MyService.class);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);

long interval = DateUtils.MINUTE_IN_MILLIS * 30;
long firstWake = System.currentTimeMillis() + interval;

am.setRepeating(AlarmManager.RTC_WAKEUP, firstWake, interval, pendingIntent);

Refactorings

Inexact Alarmmanager

Resolves

Efficiency,Energy Efficiency

Affects

Solution

It is recommended to use AlarmManager.setInexactRepeating(int type, long triggerAtMillis, long intervalMillis, PendingIntent operation) to ensure that the system is able to bundle several updates together.

Links

No wakeup Alarmmanager

Resolves

Efficiency,Energy Efficiency

Affects

Solution

Use

am.setRepeating(AlarmManager.RTC, firstWake, interval, pendingIntent);

instead of

am.setRepeating(AlarmManager.RTC_WAKEUP, firstWake, interval, pendingIntent);

whereas the option AlarmManager.RTC will not wakeup the phone if it is off.

Links

Related