Android闹钟排队时间不合适

时间:2012-12-03 19:58:27

标签: android alarm

我不明白为什么我无法创建报警管理器队列。一旦发出第一个警报,其他警报就会按照级联而不是会议时间进行。 这是单击“开始”按钮时将调用的代码:

final AlarmManager[] alarmManager=new AlarmManager[50];    
Integer i =0;
final Calendar calendar = Calendar.getInstance();
public void onClick(View arg0) {

            Intent myIntent = new Intent(AndroidAlarmSMS.this, 
                                         MyAlarmService.class);

            pendingIntent = PendingIntent.getService(AndroidAlarmSMS.this, i, 
                                                     myIntent, 0);

             thatDay.set(dataPick.getYear(), dataPick.getMonth(),dataPick.getDayOfMonth(), timePicker1.getCurrentHour(), timePicker1.getCurrentMinute());

            calendar.setTimeInMillis(System.currentTimeMillis());

            long diff = (thatDay.getTimeInMillis()- calendar.getTimeInMillis());

            int sec =   (int) (diff / 1000 % 60);

                      calendar.add(Calendar.SECOND,sec);//Sec it's the difference between time selected and now
          alarmManager[i] = (AlarmManager)getSystemService(ALARM_SERVICE);
          alarmManager[i].set(AlarmManager.RTC_WAKEUP, 
                      calendar.getTimeInMillis(), pendingIntent);


           i++; 

}

1 个答案:

答案 0 :(得分:0)

您要将所有闹钟设置为calendar时间,我猜您打算使用thatDay

alarmManager[i].set(AlarmManager.RTC_WAKEUP, thatDay.getTimeInMillis(), pendingIntent);

我有几个笔记:

  • 只有一个AlarmManager,因此alarmManager最多包含50个相同系统服务的副本。
  • 您的索引i取决于用户操作,您可能比50个警报少或更多。您应该使用ArrayList和add()