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/