我已经设置了一个alarmManager,如下所示:
Intent intent = new Intent(TopActivity.this, RecordActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra(Utils.KEY_RECORD_TIME, recordLength);
intent.putExtra(Utils.KEY_REC_START_TIME, start);
saveTimeAndLength(start, recordLength);
PendingIntent pintent = PendingIntent.getActivity(TopActivity.this, 0, intent, 0);
AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarm.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pintent);
以下应该取消它,但它总是失败。我错过了什么?
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(TopActivity.this, RecordActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra(Utils.KEY_RECORD_TIME, start);
intent.putExtra(Utils.KEY_REC_START_TIME, recordLength);
PendingIntent pintent = PendingIntent.getActivity(TopActivity.this, 0, intent, 0);
try {
alarmManager.cancel(pintent);
Log.e(TAG, "Cancelling all pending intents");
} catch (Exception e) {
Log.e(TAG, "AlarmManager update was not canceled. " + e.toString());
}
我在 StackOverflow 上阅读了很多答案,但仍然无法弄清楚问题所在。
提前致谢!