未决意图/警报第二次不起作用

pending intent / alarm not working second time

我的代码是这样的,点击按钮我执行

  Calendar calendar = Calendar.getInstance();
                calendar.setTimeInMillis(System.currentTimeMillis()+(1000*5));

                Intent intent = new Intent(LogoFrontScreen.this,Doubletest.class);
                PendingIntent alarmIntent =    PendingIntent.getBroadcast(LogoFrontScreen.this,2,intent,PendingIntent.FLAG_UPDATE_CURRENT);

                alarmMgr.setExact(AlarmManager.RTC_WAKEUP,
                        calendar.getTimeInMillis(), alarmIntent);
                PendingIntent alarmIntent1 =    PendingIntent.getBroadcast(LogoFrontScreen.this,2,intent,PendingIntent.FLAG_UPDATE_CURRENT);

                alarmMgr.setExact(AlarmManager.RTC_WAKEUP,
                        calendar.getTimeInMillis()+(2000), alarmIntent1);

然后在接收器上有一个日志,但该日志只被调用一次,为什么会这样?

代替

alarmMgr.setExact

尝试

alarmMgr.setInexactRepeating

并且要安排多个警报,您需要在每次创建时都使用唯一 ID

PendingIntent alarmIntent =    PendingIntent.getBroadcast(LogoFrontScreen.this,2,intent,PendingIntent.FLAG_UPDATE_CURRENT);

每个警报的 getBroadcast 的第二个参数(即在您的情况下为 2)需要不同。

希望它能解决您的问题:)