2011-01-31 73 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總是相同)