如何设置AlarmManager设置方法两次

时间:2014-03-21 07:41:12

标签: java android

Calendar time = Calendar.getInstance();
time.setTimeInMillis(System.currentTimeMillis());

int minute = 2;
time.add(Calendar.MINUTE,minute);


AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(TimeSequenceActivity.this, TimeSequenceReceiver.class);
PendingIntent pendingIntent =
        PendingIntent.getBroadcast(TimeSequenceActivity.this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
alarmManager.set(AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), pendingIntent);


time.setTimeInMillis(System.currentTimeMillis());
int another_minute = 1;
time.add(Calendar.MINUTE,another_minute);
alarmManager.set(AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), pendingIntent);

我要设置AlaramManager两次。 例如)想要在2分钟内设置闹钟,并在第1次闹钟后设置1分钟。因此,键入上面的代码并执行应用程序,它现在正在工作,警报只在3分钟内触发一次。

提前感谢你..

1 个答案:

答案 0 :(得分:0)

我刚刚从别人的问题中解决了这个问题。 解决方案如下。

PendingIntent.getBroadcast(TimeSequenceActivity.this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
alarmManager.set(AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), pendingIntent);

PendingIntent.getBroadcast(TimeSequenceActivity.this, 1, intent, PendingIntent.FLAG_ONE_SHOT);
alarmManager.set(AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), pendingIntent);

如果我想设置不同的alarams,则应该是requestCode中的另一个PendingIntent