Implementation
Efficiency,Energy Efficiency
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);
Efficiency,Energy Efficiency
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.
Efficiency,Energy Efficiency
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.