本文介绍了警报管理器在Android中立即触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
奇怪的是,即使当前时间大于一天后运行的警报时间,即使我提出了条件,我的警报管理器也会立即调用待处理的意图。
Strangely, my Alarm Manger is calling the pending intent immediately, even though I have put a condition if the current time is greater than alarm time run one day later.
p>
I have alarm Manger to trigger everyday at 10PM.
Intent startServiceIntent = new Intent(this, numbers.class); this.startService(startServiceIntent); Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(res.getString(R.string.hoursvalue))); //10 cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.AM_PM, Calendar.PM); cal.set(Calendar.MILLISECOND, 0); long alarmtime = cal.getTimeInMillis(); Log.e("ALarm","Time"+alarmtime); if (currenttime > alarmtime) { alarmtime = alarmtime + AlarmManager.INTERVAL_DAY; Log.e("Current Time","Greater"+alarmtime); } if (currentapiVersion >= 19) { AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent2 = new Intent(this, ServiceForLoadingOnlineNumbers.class); PendingIntent pi = PendingIntent.getService(this, 741258963, intent2, 0); am.setInexactRepeating(AlarmManager.RTC_WAKEUP, alarmtime, AlarmManager.INTERVAL_DAY, pi); } else if (currentapiVersion >= 16 && currentapiVersion < 19) { AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent3 = new Intent(this, ServiceForLoadingOnlineNumbers.class); PendingIntent pi = PendingIntent.getService(this, 741258963, intent3, 0); am.setRepeating(AlarmManager.RTC_WAKEUP, alarmtime, AlarmManager.INTERVAL_DAY, pi); }日志会以毫秒为单位正确显示第二天,但会立即触发。
The Log shows the next day in milliseconds correctly but triggers immediately. What could be the issue here?
推荐答案我建议检查警报管理器是否为空,然后在设置警报之前取消警报。以我为例:
I suggest checking if the alarm manager is null then canceling the alarm before setting the alarm this took me some time example
if(alarmManger != null){ alarmManger.cancel(operation); alarmManger.setRepeating(alarmType,alarmtime,AlarmManager.INTERVAL_DAY, operation); }更多推荐
警报管理器在Android中立即触发
发布评论