我每24小时在重复模式下设置一个闹钟。因此,警报接收器应该只在一次设置的时间内调用,但它会重复调用。为什么呢?
这是我附上我的代码来设置闹钟:
AlarmManager alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent objIntent = new Intent(this, PedometerAlarmReciever.class);
PendingIntent alarmIntent = PendingIntent.getBroadcast(this, 0, objIntent, 0);
// Set the alarm to start at 21:32 PM
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR, 11);
calendar.set(Calendar.MINUTE, 20);
calendar.set(Calendar.AM_PM, Calendar.AM);
// setRepeating() lets you specify a precise custom interval--in this case,
// 1 day
alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, alarmIntent);