我已經安裝了alarmManager如下:如何取消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的很多答案,但仍然無法弄清楚是什麼問題。
在此先感謝!
有人已經提到,額外的數據密鑰反轉(啓動和RECORDLENGTH)?'intent.putExtra(Utils.KEY_RECORD_TIME,RECORDLENGTH) ; intent.putExtra(Utils.KEY_REC_START_TIME,start);'與'intent.putExtra(Utils.KEY_RECORD_TIME,start); intent.putExtra(Utils.KEY_REC_START_TIME,recordLength);' - 它不應該導致過濾麻煩,雖然... – Johannes 2016-09-09 14:30:44