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

android– 为什么AlarmManager.setRepeating中的triggerAtTime不起作用,第1张

概述AlarmManagermgr=(AlarmManager)ctxt.getSystemService(Context.ALARM_SERVICE);Intenti=newIntent(ctxt,AlarmReceiver.class);PendingIntentpi=PendingIntent.getBroadcast(ctxt,0,i,0);mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,

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);

根据androID doc

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

该动作应该在1秒后开始,但它永远不会被调用,为什么?

解决方法:

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

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

以上是内存溢出为你收集整理的android – 为什么AlarmManager.setRepeating中的triggerAtTime不起作用全部内容,希望文章能够帮你解决android – 为什么AlarmManager.setRepeating中的triggerAtTime不起作用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1116576.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存