@Override
  protected void onHandleIntent(Intent intent) {
    int serviceMode = intent.getIntExtra(SERVICE_MODE, MODE_ALL_REMINDS);
    switch (serviceMode) {
      case MODE_ALL_REMINDS:
        Log.i(TAG, "NotificationService called to update alarm");

        List<Remind> waitingReminds =
            RemindDatabase.getInstance().getStoredData(DatabaseHelper.FILTER_WAITING_REMINDS);
        for (Remind remind : waitingReminds) {
          if (remind.getNotificationMillis() >= System.currentTimeMillis()) {
            setAlarm(remind.getId(), remind.getNotificationMillis(), remind.getTitle());
          }
        }
        break;

      case MODE_ONE_REMIND:
        Log.i(TAG, "NotificationService called to set one alarm");

        int setAlarmId = intent.getIntExtra(DatabaseHelper.COLUMN_ID, 0);
        long alarmMillis = intent.getLongExtra(DatabaseHelper.COLUMN_MILLIS, 0);
        String alarmMessage = intent.getStringExtra(DatabaseHelper.COLUMN_TITLE);
        setAlarm(setAlarmId, alarmMillis, alarmMessage);
        break;

      case MODE_UPDATE_ALARM:
        Log.i(TAG, "NotificationService called to update alarm");

        int updateAlarmId = intent.getIntExtra(DatabaseHelper.COLUMN_ID, 0);
        updateAlarm(updateAlarmId);
        break;
    }
  }
  private void updateAlarm(int id) {
    Remind remind = RemindDatabase.getInstance().get(id);
    Intent pendingOperationContent = new Intent(mContext, AlarmService.class);
    PendingIntent pendingOperation =
        PendingIntent.getService(mContext, id, pendingOperationContent, 0);

    mAlarmManager.cancel(pendingOperation);
    pendingOperation.cancel();

    switch (remind.getStatus()) {
      case RemindUtil.STATUS_DONE:
        Log.i(TAG, "Dismiss alarm, id: " + id);
        break;

      case RemindUtil.STATUS_WAIT:
        if (remind.getNotificationMillis() > System.currentTimeMillis()) {
          setAlarm(id, remind.getNotificationMillis(), remind.getTitle());
          Log.i(TAG, "Set removed alarm back, id: " + id);
        }
        break;
    }
  }