The Android 5.0 Lollipop (API 21) release introduces a job scheduler API via the Job Scheduler class.

Compared to a custom Sync Adapter or the alarm manager, the Job Scheduler supports batch scheduling of jobs.

The Android system can combine jobs so that battery consumption is reduced.

Non compliant Code Example

void setAlarm(Context context) {
    AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, Alarm.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 60 * 10, pendingIntent);
}

Alarm alarm = new Alarm();
alarm.setAlarm(this);

Compliant Code Example

JobInfo info = new JobInfo.Builder(123, COMPONENT_NAME)
                          .setRequiresCharging(true)
                          .setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
                          .setPersisted(true)
                          .setPeriodic(10 * 60 * 1000)
                          .build();
JobScheduler scheduler = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE);
scheduler.schedule(info);