@Override
  public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);

    log.debug("onReceive(context, {})", intent);

    backgroundScheduler.scheduleBackupService();
    backgroundScheduler.scheduleMidnightRefresh();
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);

    long taskId = intent.getLongExtra(AstridApiConstants.EXTRAS_TASK_ID, -1);
    if (taskId == -1) {
      return;
    }

    Task task = taskService.fetchById(taskId, Task.PROPERTIES);
    if (task == null || !task.isCompleted()) {
      return;
    }

    String recurrence = task.sanitizedRecurrence();
    boolean repeatAfterCompletion = task.repeatAfterCompletion();

    if (recurrence != null && recurrence.length() > 0) {
      long newDueDate;
      try {
        newDueDate = computeNextDueDate(task, recurrence, repeatAfterCompletion);
        if (newDueDate == -1) {
          return;
        }
      } catch (ParseException e) {
        log.error(e.getMessage(), e);
        return;
      }

      long oldDueDate = task.getDueDate();
      long repeatUntil = task.getRepeatUntil();

      if (repeatFinished(newDueDate, repeatUntil)) {
        return;
      }

      rescheduleTask(context, gcalHelper, taskService, task, newDueDate);

      // send a broadcast
      Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_EVENT_TASK_REPEATED);
      broadcastIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, task.getId());
      broadcastIntent.putExtra(AstridApiConstants.EXTRAS_OLD_DUE_DATE, oldDueDate);
      broadcastIntent.putExtra(AstridApiConstants.EXTRAS_NEW_DUE_DATE, newDueDate);
      context.sendOrderedBroadcast(broadcastIntent, null);
      Flags.set(Flags.REFRESH);
    }
  }