我在9:00和21:00有两个AlarmManager,但只运行第二个警报。
////////9:00am/////////
Intent aviso = new Intent(FijarAlerta.this,Servicio.class);
PendingIntent pi = PendingIntent.getService(FijarAlerta.this, 0, aviso, PendingIntent.FLAG_UPDATE_CURRENT);
//set the hour
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 9);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(),AlarmManager.INTERVAL_DAY,pi);
第二次警报
////////21:00pm//////////
Intent avisopm = new Intent(FijarAlerta.this,Servicio.class);
PendingIntent pipm = PendingIntent.getService(FijarAlerta.this, 0, avisopm, PendingIntent.FLAG_UPDATE_CURRENT);
//set the hour
Calendar calpm = Calendar.getInstance();
calpm.set(Calendar.HOUR_OF_DAY, 21);
calpm.set(Calendar.MINUTE, 0);
calpm.set(Calendar.SECOND, 0);
AlarmManager ampm = (AlarmManager)getSystemService(ALARM_SERVICE);
ampm.setRepeating(AlarmManager.RTC_WAKEUP,calpm.getTimeInMillis(),AlarmManager.INTERVAL_DAY,pipm);
答案 0 :(得分:1)
对PendingIntent.getService()
的调用的第二个参数在每种情况下都应该是不同的数字。例如:
PendingIntent pi = PendingIntent.getService(FijarAlerta.this, 111, aviso, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pipm = PendingIntent.getService(FijarAlerta.this, 222, avisopm, PendingIntent.FLAG_UPDATE_CURRENT);
目前第二个pendingIntent只是覆盖了第一个
答案 1 :(得分:0)
只需更换第二条警报线:
PendingIntent pipm = PendingIntent.getService(FijarAlerta.this, 0, avisopm, PendingIntent.FLAG_UPDATE_CURRENT);
以下
PendingIntent pipm = PendingIntent.getService(FijarAlerta.this, 1, avisopm, PendingIntent.FLAG_UPDATE_CURRENT);
现在,如果你没有成功,请试着让我发表评论。
享受编码。 :)