android Alarmmanager 不会长时间重复
我确信我做错了什么,但当我设置警报执行以下操作时,我无法让警报管理器多次触发:
AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, ReminderAlarmReceiver.class);
i.setData(Uri.parse(REMINDER_ID + getReminderID() + getTriggerAtTime()));
i.putExtra(REMINDER_ID, reminderID);
i.putExtra(DiaryListItem.DIARY_ID, parentDiaryID);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
mgr.setRepeating(AlarmManager.RTC_WAKEUP, triggerAtTime, AlarmManager.INTERVAL_DAY;, pi);
它似乎在第一天触发,但在第二天不会触发。当我尝试每周或每月发出警报时,也会发生同样的情况。有没有更好的方法来设置长期警报?
I'm sure I'm doing something wrong but I can't get the alarm manager to trigger more than once when I setup an alarm doing the following:
AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, ReminderAlarmReceiver.class);
i.setData(Uri.parse(REMINDER_ID + getReminderID() + getTriggerAtTime()));
i.putExtra(REMINDER_ID, reminderID);
i.putExtra(DiaryListItem.DIARY_ID, parentDiaryID);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
mgr.setRepeating(AlarmManager.RTC_WAKEUP, triggerAtTime, AlarmManager.INTERVAL_DAY;, pi);
It seems to trigger the first day but doesn't trigger the next day. The same thing happens when I try to make a weekly or monthly alarm. Is there a better way of setting up long term alarms?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否打算将分号放入 .setRepeating 中?我想如果它实际上仍然存在,你的运行将会崩溃:
应该是
如果这只是一个拼写错误,你的 logcat 会给出任何类型的错误吗?
Did you mean to put that semicolon in your .setRepeating? I imagine your run would crash if it were actually still there:
should be
If that was just a typo, does your logcat give any kind of error?