예제 #1
0
  /**
   * This will set the alarm instance to the FIRED_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 setFiredState(Context context, AlarmInstance instance) {
    LogUtils.v("Setting fire state to instance " + instance.mId);

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

    if (instance.mAlarmId != null) {
      // if the time changed *backward* and pushed an instance from missed back to fired,
      // remove any other scheduled instances that may exist
      AlarmInstance.deleteOtherInstances(contentResolver, instance.mAlarmId, instance.mId);
    }

    // Start the alarm and schedule timeout timer for it
    AlarmService.startAlarm(context, instance);

    Calendar timeout = instance.getTimeout(context);
    if (timeout != null) {
      scheduleInstanceStateChange(context, timeout, instance, AlarmInstance.MISSED_STATE);
    }

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