[英]Android AlarmManager not firing at set time
I have an AlarmManager
that is supposed to fire off on the 26th of December 2013. Here is my code: 我有一个
AlarmManager
,应该在2013年12月26日启动。这是我的代码:
FestCountdownTimer countdownNotificationTimer = new FestCountdownTimer(
00, 00, 9, 26, 11, 2013);
long timeToEvent = countdownNotificationTimer.getIntervalMillis();
System.out
.println("TIME TO EVENT!!! ------------------ " + timeToEvent);
Intent eventAlarm = new Intent(this, AlarmReceiver.class);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, timeToEvent, PendingIntent
.getBroadcast(this, 1, eventAlarm,
PendingIntent.FLAG_UPDATE_CURRENT));
But, my alarm is firing off after 1 or 2 minutes. 但是,我的闹钟在1或2分钟后响起。 I don't know what seems to be wrong.
我不知道什么地方错了。 (Byt the way, the
FestCountdownTimer
is a class I made to get the interval between now and the future set date. The long timeToEvent;
is coming properly.) (顺便说一句,
FestCountdownTimer
是我制作的一个类,用于获取现在和将来的设置日期之间的时间间隔long timeToEvent;
正常出现。)
Thanks for the help... 谢谢您的帮助...
I dont know about your FestCountdownTimer class but damn sure probablay time not set properly(I mean may be mistaken convert time to millisecond)
我不知道您的FestCountdownTimer类,但是该死确保probablay时间设置不正确(我的意思是将时间转换为毫秒可能是错误的)
Note: This below code is harcode not tested by in actual app 注意: 以下代码未经实际应用测试
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
cal.clear();
cal.set(year,month,day,hour,min); //set your date here
AlarmManager alarmMgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
// cal.add(Calendar.SECOND, 5);
alarmMgr.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.