我有一个闹钟设置为每天8点钟用这个代码关闭。AlarmManager启动超过一次报警setRepeating()时间
String alarm = Context.ALARM_SERVICE;
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 8);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND,0);
calendar.set(Calendar.MILLISECOND, 0);
AlarmManager am = (AlarmManager)getActivity().getSystemService(alarm);
Intent intent = new Intent("NEW_ITEM");
PendingIntent sender = PendingIntent.getBroadcast(getActivity(), 0, intent, 0);
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, sender);
Log.e("RELEASE LIST", "ALARM Set For 1 day from " + calendar.getTimeInMillis());
唯一的问题是警报不止一次熄灭。我不想要这个。因为同样的信息会不断重复出现,这会非常烦人。我的代码中是否有东西存在,或者需要做什么来解决这个问题?
编辑:
if(doc != null){
item = doc.select("tr> td.indexList1, tr > td.indexList2");
if(item != null){
// Iterator over those elements
ListIterator<Element> postIt = item.listIterator();
while (postIt.hasNext()) {
Element name = postIt.next();
nameOf = name.text();
form = postIt.next().text();
Element url = name.select("a").first();
urlString = url.attr("href");
genre = postIt.next().text();
Date = postIt.next().text();
Log.v("Dates", Date);
if(Date.contains(dayOfMonth)){
i++;
}
}
}
}
return null;
}
@Override
protected void onPostExecute(Void notUsed){
if(i == 0){
}
else{
if(i==1){
nm = (NotificationManager) ReleaseService.this
.getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence from = "GameIT";
CharSequence message = "You have "+i +" Today!";
PendingIntent contentIntent = PendingIntent.getActivity(gameReleaseService.this, 0, new Intent(ReleaseService.this, Htmlparser.class), 0);
Notification notif = new Notification(R.drawable.icon,
"You have "+i +" Released Today!" , System.currentTimeMillis());
notif.defaults |= Notification.DEFAULT_VIBRATE;
notif.setLatestEventInfo(ReleaseService.this, from, message, contentIntent);
nm.notify(i, notif);
}else{
nm = (NotificationManager) ReleaseService.this
.getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence from = "GameIT";
CharSequence message = +i+ " released today!";
PendingIntent contentIntent = PendingIntent.getActivity(ReleaseService.this, 0, new Intent(ReleaseService.this, Htmlparser.class), 0);
Notification notif = new Notification(R.drawable.icon,
"You have "+i+" that released today!" , System.currentTimeMillis());
notif.defaults |= Notification.DEFAULT_VIBRATE;
notif.setLatestEventInfo(ReleaseService.this, from, message, contentIntent);
nm.notify(i, notif);
}
}
}
'不止一次'你是什么意思?发生什么事? –
每天8点后正式启动。它像其他几个小时左右一样熄灭。 –
你的代码似乎是正确的..告诉我们关于活动给我们展示一些可能是错误的代码!它有没有重试它正在重试?没有? –