我在android中实现了一个闹钟,但大多数时候它通知得很晚。
在我的应用程序中,我可以一次创建多个闹钟,但如果这样做,则只有最后一个闹钟会通知。
请帮我找到解决方案。
Calendar calendar1 = Calendar.getInstance();
calendar1.set(Calendar.HOUR_OF_DAY, 11);
calendar1.set(Calendar.MINUTE, 55);
calendar1.set(Calendar.SECOND, 0);
calendar1.set(Calendar.AM_PM,Calendar.AM);
Intent myIntent1 = new Intent(MainActivity.this, MyReceiver.class);
pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, myIntent1,0);
AlarmManager alarmManager1 = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager1.setRepeating(AlarmManager.RTC, calendar1.getTimeInMillis(),3600000, pendingIntent);
最佳答案
如mentioned , 安卓 no longer triggers the alarm at the exact time, unless you explicitly request it :
Note: Beginning with API 19 (KITKAT) alarm delivery is inexact: the OS will shift alarms in order to minimize wakeups and battery use. There are new APIs to support applications which need strict delivery guarantees; see
setWindow
(int, long, long, PendingIntent) andsetExact
(int, long, PendingIntent). Applications whose targetSdkVersion is earlier than API 19 will continue to see the previous behavior in which all alarms are delivered exactly when requested.
这是不可能的重复警报,重复警报总是在系统认为最好时触发:
As of API 19, all repeating alarms are inexact.
关于多个闹钟的问题seems solved .
关于Android 闹钟管理器通知晚了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29554883/