gpt4 book ai didi

android - 为什么 AlarmManager.setRepeating 中的 triggerAtTime 不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 11:40:24 25 4
gpt4 key购买 nike

AlarmManager mgr=
(AlarmManager)ctxt.getSystemService(Context.ALARM_SERVICE);
Intent i=new Intent(ctxt, AlarmReceiver.class);
PendingIntent pi=PendingIntent.getBroadcast(ctxt, 0, i, 0);
mgr.setRepeating(
AlarmManager.ELAPSED_REALTIME_WAKEUP,
System.currentTimeMillis() + 1000,
1000, pi);

根据安卓文档

triggerAtMillis time in milliseconds that the alarm should first go off, using the appropriate clock (depending on the alarm type).

Action 应该在 1 秒后立即开始,但它从未被调用,为什么?

最佳答案

在 setRepeating() 方法中不要使用 AlarmManager.ELAPSED_REALTIME_WAKEUP,而是使用 AlarmManager.RTC_WAKEUP,如下所示,

mgr.setRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis() + 1000, 1000, pi);

关于android - 为什么 AlarmManager.setRepeating 中的 triggerAtTime 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13412685/

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