【发布时间】:2012-03-09 23:27:59
【问题描述】:
所以我一直在尝试从我的活动中设置多个警报,这将调用我处理写入文本文件的服务。 但无论出于何种原因,我根本无法让它正常工作。最简单的形式是:
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();
在这个最新的迭代中,只有最新的一个会在正确的时间真正调用我的服务。我之前的那个被忽略了。
理想情况下,我希望能够在不同时间从不同的不同计时器调用相同的服务。我知道上面的代码并没有完全做到这一点,但这实际上只是一个测试,以了解它是如何工作的。但正如你所看到的,它确实没有。任何帮助都将不胜感激,因为我已经为此苦苦挣扎了很长时间。
【问题讨论】: