Ejemplo n.º 1
0
  /**
   * This will set the alarm instance to the MISSED_STATE and update the application notifications
   * and schedule any state changes that need to occur in the future.
   *
   * @param context application context
   * @param instance to set state to
   */
  public static void setMissedState(Context context, AlarmInstance instance) {
    LogUtils.v("Setting missed state to instance " + instance.mId);
    // Stop alarm if this instance is firing it
    AlarmService.stopAlarm(context, instance);

    // Check parent if it needs to reschedule, disable or delete itself
    if (instance.mAlarmId != null) {
      updateParentAlarm(context, instance);
    }

    // Update alarm state
    ContentResolver contentResolver = context.getContentResolver();
    instance.mAlarmState = AlarmInstance.MISSED_STATE;
    AlarmInstance.updateInstance(contentResolver, instance);

    // Setup instance notification and scheduling timers
    AlarmNotifications.showMissedNotification(context, instance);
    scheduleInstanceStateChange(
        context, instance.getMissedTimeToLive(), instance, AlarmInstance.DISMISSED_STATE);

    // Instance is not valid anymore, so find next alarm that will fire and notify system
    updateNextAlarm(context);
  }