我尝试通过服务进行简单的提醒和通知。我选择了一些动作的时间,我想在那个时间结束前10分钟设置通知。它工作一次,我将计时器设置为12分钟,我在2分钟后收到通知。但随后我每隔25-35分钟收到随机通知 当然,我可以一次收到很少的通知而且它们有效,但后来我得到了随机通知,我不知道如何阻止它们......我应该在发送通知后向服务发送通知ID并停止服务吗?
计时器代码:
Intent intent = new Intent(Review.this, AlarmService.class);
PendingIntent pintent = PendingIntent.getService(Review.this, unique, intent, PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarm.set(AlarmManager.RTC_WAKEUP, currTimestamp - (10 * 60000), pintent);
和服务代码:
notifyMgr=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notifyObj=new Notification(R.drawable.icon, "alarm", System.currentTimeMillis());
PendingIntent i=PendingIntent.getActivity(this, 0, new Intent(this, MainList.class), 0);
notifyObj.setLatestEventInfo(this, "10 min to finish", "Click here to see list", i);
notifyObj.defaults |= Notification.DEFAULT_VIBRATE;
notifyObj.defaults |= Notification.DEFAULT_SOUND;
notifyObj.flags|=Notification.FLAG_ONLY_ALERT_ONCE;
notifyMgr.notify(1, notifyObj);
我尝试Flags:一次拍摄但只提醒一次,但我仍然得到这个随机通知:/ 也许整个代码都错了......不知道