如何避免在设置时间触发警报?
How to avoid alarm trigger at time of set?
我设置的闹钟间隔为 2 小时。它工作得非常完美,但问题是,在设置时它会触发警报。
不用在设定的休息时间触发闹钟就可以了。
Intent _myIntent = new Intent(activity, MyReceiverStartPush.class);
_myIntent.putExtra("msg", "Feed");
PendingIntent _myPendingIntent = PendingIntent.getBroadcast(
activity, 0, _myIntent, 0);
AlarmManager _myAlarmManager = (AlarmManager) activity
.getSystemService(Service.ALARM_SERVICE);
_myAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis(), (AlarmManager.INTERVAL_HOUR)
* 2, _myPendingIntent);
而不是使用 System.currentTimeMillis()
(这就是原因)你应该在那里使用 System.currentTimeMillis() + 2H
我设置的闹钟间隔为 2 小时。它工作得非常完美,但问题是,在设置时它会触发警报。 不用在设定的休息时间触发闹钟就可以了。
Intent _myIntent = new Intent(activity, MyReceiverStartPush.class);
_myIntent.putExtra("msg", "Feed");
PendingIntent _myPendingIntent = PendingIntent.getBroadcast(
activity, 0, _myIntent, 0);
AlarmManager _myAlarmManager = (AlarmManager) activity
.getSystemService(Service.ALARM_SERVICE);
_myAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis(), (AlarmManager.INTERVAL_HOUR)
* 2, _myPendingIntent);
而不是使用 System.currentTimeMillis()
(这就是原因)你应该在那里使用 System.currentTimeMillis() + 2H