先创建闹钟
AlarmManager manager = (AlarmManager)getSystemService(ALARM_SERVICE);
Long seconds = Utils.getseconds(num1,num2,flag);
long triggerAttime = SystemClock.elapsedRealtime()+seconds;
Intent i = new Intent(this,AlarmReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(this,count1++,i,0);
//用count的不同来实现任务不会被覆盖
manager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP,triggerAttime,pi);
【Android删除Alarm的方法】这是删除的方法
Intent intent = new Intent(context, AlarmReceiver.class);
context是当前活动上下文
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,plan.get(position).getCount(),intent,PendingIntent.FLAG_UPDATE_CURRENT);
//第二个参数是requestCode 即要删除闹钟的code。最后一个参数是PendingIntent.FLAG_UPDATE_CURRENT
AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
//cancel()方法删除闹钟