-1

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

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++; 

}
4

1 回答 1

0

您将所有警报设置为在calendar' 时间发生,我猜您打算使用thatDay

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

我有几点注意事项:

  • AlarmManager 只有一个,因此alarmManager最多可以包含同一系统服务的 50 个副本。
  • 您的索引i取决于用户的操作,您可能有少于或多于50 个警报。您应该使用 ArrayList 和add().
于 2012-12-04T00:16:52.207 回答