gpt4 book ai didi

java - AlarmManager 在两个特定时间

转载 作者:行者123 更新时间:2023-12-01 14:53:29 26 4
gpt4 key购买 nike

我在 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);

最佳答案

调用 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刚刚覆盖第一个

关于java - AlarmManager 在两个特定时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14560340/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com