Android-AlarmManager多个闹钟相互独立的实现

Intent i=new Intent(TimeSetActivity.this,AlarmReceiver.class);  
PendingIntent pi = PendingIntent.getBroadcast(TimeSetActivity.this, Integer.valueOf(id) , i, 0); //通过getBroadcast第二个参数区分闹钟,将查询得到的note的ID值作为第二个参数。

AlarmManager am = (AlarmManager) getSystemService(Activity.ALARM_SERVICE); 
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pi);//设置闹铃 

 

Intent i=new Intent(TimeSetActivity.this,AlarmReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(TimeSetActivity.this, Integer.valueOf(id) , i, 0);     
am.cancel(pi);//取消闹钟
这样就通过getBroadcast的第二个参数有效的区分了各个闹钟

你可能感兴趣的:(service)