当我没有声明时,AlarmManager 可以完美运行,cancel
但在声明 .. 时不会触发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
一两分钟后……但每当我使用cancel
代码时,都AlarmManager
不会触发……提前致谢!:)