所以我一直在试图从我的活动中设置多个闹钟,这将会打电话给我的服务,该服务处理写入文本文件。 但无论出于什么原因,我根本无法让它正常工作。在我最简单的形式中,我有:设置多个闹钟来呼叫服务
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
AlarmManager pm = (AlarmManager)getSystemService(ALARM_SERVICE);
PendingIntent myIntent = PendingIntent.getService(MyLifeActivity.this, 0, new Intent(MyDogsLifeActivity.this, TimerService.class), 0);
PendingIntent myIntent2 = PendingIntent.getService(MyLifeActivity.this, 0, new Intent(MyDogsLifeActivity.this, TimerService.class), 0);
Calendar tomorrow = new GregorianCalendar();
tomorrow.setTimeInMillis(System.currentTimeMillis());
tomorrow.clear();
tomorrow.set(2012,2,9,17,21); // set for today 3/9/2012 at 5:21 PM.
am.setRepeating(AlarmManager.RTC_WAKEUP, tomorrow.getTimeInMillis(), fONCE_PER_DAY, myIntent);
Toast.makeText(MyLifeActivity.this, "AM Set for "+ tomorrow.getTime() ,Toast.LENGTH_LONG).show();
Calendar tomorrow1 = new GregorianCalendar();
tomorrow1.setTimeInMillis(System.currentTimeMillis());
tomorrow1.clear();
tomorrow1.set(2012,2,9,17,22); // set for today 3/9/2012 at 5:22 PM.
pm.setRepeating(AlarmManager.RTC_WAKEUP, tomorrow1.getTimeInMillis(), fONCE_PER_DAY, myIntent2);
Toast.makeText(MyLifeActivity.this, "PM Set for "+ tomorrow1.getTime() ,Toast.LENGTH_LONG).show();
在这个最新的迭代中,只有最新的一个实际上会在正确的时间调用我的服务。我之前的一个简单地被忽略。
理想情况下,我希望能够在不同的时间从不同的定时器调用相同的服务。我知道上面的代码并没有完全做到这一点,但这只是一个测试,以了解这是如何工作的。但是,正如你所看到的那样,它确实没有。任何帮助将非常感激,因为我一直在为此奋斗很长很长一段时间。
就是这样!我没有意识到我正在两次同一个对象。将0更改为其他内容确实有效。谢谢! – FirmwareEngineer 2012-03-10 14:45:39