2011-01-31 78 views
1

我使用下面的代码来创建警报。在Android中设置更多闹钟?

String strDateTime=strDate+" "+strTime;    
      DateFormat dfm = new SimpleDateFormat("yyyy-MM-dd HH:mm");    
      Date alarmTime = null; 
      try { 
       alarmTime = dfm.parse(strDateTime); 
      } catch (ParseException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 

      long setAlarmTime=alarmTime.getTime(); 

      Intent myIntent = new Intent(context, MyAlarmService.class); 
      pendingIntent = PendingIntent.getService(context, 0, myIntent, 0); 

      AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE); 

      //set time and get the Intent 
      alarmManager.set(AlarmManager.RTC_WAKEUP, setAlarmTime, pendingIntent); 

如果我设置了多个闹钟,最后一个闹钟将被执行。如何在android中添加更多闹钟时间?

回答

1

尝试在每AlarmManager.set呼叫

AlaramManager复位报警,先前为同一PendingIntent设置让每一个你Intent(代码myIntent)一些随机数据(通过setDat调用)(和你的PendingIntents总是相同)