gpt4 book ai didi

java - 设置多个警报/通知错误/错误?

转载 作者:行者123 更新时间:2023-12-01 15:56:37 26 4
gpt4 key购买 nike

我正在尝试制作一个应用程序,允许用户为每个任务设置任务和警报或通知。我在下面创建了一个“setAlarm”方法。但是,我有一个错误,每当我设置带有警报的多个任务时,不知何故,所有先前的任务都会被取消,并且只有最近设置的警报才会响起。你知道问题出在哪里吗?我的猜测是,每次我调用“setAlarm”时,“日历”实例都会重置。我该如何解决这个问题?

  public void setAlarm() {
Intent intent1 = new Intent(NewGoal.this, SingleAlarm.class);
PendingIntent sender = PendingIntent.getBroadcast(NewGoal.this,
0, intent1, 0);

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

if (alarm_time == 10) {
calendar.add(Calendar.SECOND, alarm_time);
} else if (alarm_time == 30 {
calendar.add(Calendar.SECOND, alarm_time)
}

AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
Log.i(TEST, "In setAlarm method");
Log.i(TEST, "calendar=" + calendar.MILLISECOND);
}

最佳答案

来自documentation :

If there is already an alarm scheduled for the same IntentSender, it will first be cancelled.

关于java - 设置多个警报/通知错误/错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4929062/

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