"snoozing" 警报有问题

Having problems with "snoozing" alarm

有谁知道如何使用贪睡功能以及我哪里出错了?

我的默认小睡时间是 5 分钟。它工作正常,直到重新启动
应用程序,然后不再工作。 如果我清除缓存和数据它再次工作。

 public void onClick(View view) {

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    int iSnoozeLeft = settings.getInt(PuzzleAlarm.SNOOZE_LEFT, 1);
    if (iSnoozeLeft != 0) {
      Intent activate = new Intent(AlarmNotification.this, AlarmReceiver.class);
      PendingIntent alarmIntent = PendingIntent.getBroadcast(AlarmNotification.this, 0, activate, 0);
      AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

      int iMinutes = Preferences.getSnooze(settings, AlarmNotification.this);
      Calendar calendar = Calendar.getInstance();
      calendar.roll(Calendar.MINUTE, iMinutes);
      alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent);

      SharedPreferences.Editor editor = settings.edit();
      editor.putInt(PuzzleAlarm.SNOOZE_LEFT, iSnoozeLeft - 1); // disabling
      // Commit the edits!
      editor.commit();
    }`

PendingIntent.getBroadcast(AlarmNotification.this, 0, activate, 0);

确保您没有使用“0”作为您的其他警报 ID。在其他情况下,您的 "snooze" 代码将覆盖之前的警报。