当我不申明 cancel 时,AlarmManager 能很好的运行。但是当我申明cancel时,也不能取消。Calendar c= Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 37);
c.set(Calendar.SECOND, 0);
Toast.makeText(this, c.getTime().toString(), Toast.LENGTH_LONG).show();
intent = new Intent(TestAlarm.this, TestAlarmService.class);
pi = PendingIntent.getService(TestAlarm.this, 1, intent, 0);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), pi);cancel 代码:c.add(Calendar.HOUR_OF_DAY, 0);
c.add(Calendar.MINUTE, 38);
c.add(Calendar.SECOND, 0);
PendingIntent pi1=PendingIntent.getService(TestAlarm.this, 1, intent, 0);
AlarmManager am1 = (AlarmManager) getSystemService(ALARM_SERVICE);
//stopService(intent);
am1.cancel(pi);现在我想开启 AlarmManager,在 12:37 响铃,然后在一两分钟内取消。但是当我使用 Cancel代码,AlarmManager 不能取消。 什么原因啊?
添加回答
举报
0/150
提交
取消