gpt4 book ai didi

java - 检查 AlarmManager 任务是否正在进行

转载 作者:太空狗 更新时间:2023-10-29 13:53:57 26 4
gpt4 key购买 nike

我正在使用 AlarmManager 运行定期后台任务:

AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 10 * 60 * 1000, pendingIntent);

我放了一个标志 PendingIntent.FLAG_UPDATE_CURRENT,但我担心如果我再次运行这段代码它会重新编写我的日程安排。问题:

  • 是否会重置时间,我必须等待 10 分钟才能收到事件?
  • 有没有办法检查我是否设置了闹钟任务计划?

最佳答案

Will it reset the time and I'll have to wait for 10 mins to receive an event?

是的,会的。根据文档:

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

根据

Is there a way to check if my alarm task schedule is set?

是的,there is几个解决方案,您可以检查。

另外,请注意 setRepeating不准确的

Note: as of API 19, all repeating alarms are inexact. If your application needs precise delivery times then it must use one-time exact alarms, rescheduling each time as described above. Legacy applications whose targetSdkVersion is earlier than API 19 will continue to have all of their alarms, including repeating alarms, treated as exact.

关于java - 检查 AlarmManager 任务是否正在进行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41793577/

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