我正在尝试使用警报管理器设置多个警报。我的问题是,只有我设置的第一个警报有效。第一次警报后设置的每个警报均不起作用。这是设置警报的功能:
private void setAlarm(long time){
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this,MyAlarm.class);
int id = (int) System.currentTimeMillis();
PendingIntent pendingIntent = PendingIntent.getBroadcast(this,id,intent,PendingIntent.FLAG_ONE_SHOT);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,time,alarmManager.INTERVAL_DAY,pendingIntent);
}
在我的onCreate函数中,我所有的时间选择器都带有一个onClickListener,它在选择时间时会调用此函数。
time1.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
// TODO Auto-generated method stub
Calendar mcurrentTime = Calendar.getInstance();
int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
int minute = mcurrentTime.get(Calendar.MINUTE);
TimePickerDialog mTimePicker;
mTimePicker = new TimePickerDialog(TimeSet.this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
int hour = selectedHour % 12;
time1begin.setText(String.format("%02d:%02d %s", hour == 0 ? 12 : hour,
selectedMinute, selectedHour < 12 ? "am" : "pm"));
}
}, hour, minute, true);
mTimePicker.setTitle("Select Time");
mTimePicker.show();
setAlarm(mcurrentTime.getTimeInMillis());
}
});
如何设置多个警报?