我已经创建了如下所示的警报
Intent intent = new Intent(this, Areceiver.class);
PendingIntent sender = PendingIntent.getBroadcast(this, 1234567, intent, 0);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, timenow, 3000, sender);
我创建了一个按钮来停止警报。在 onclick 方法中,我编写了以下代码
Intent intentstop = new Intent(this, Areceiver.class);
PendingIntent senderstop = PendingIntent.getBroadcast(this,
0, intentstop, 0);
AlarmManager alarmManagerstop = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManagerstop.cancel(senderstop);
但工作并没有停止。可能是什么问题?
最佳答案
您在启动警报时为您的待处理 Intent 提供了 request_code = 1234567。但是当您尝试停止它时,您使用的是 0。尝试停止时使用它并且应该可以工作
Intent intentstop = new Intent(this, Areceiver.class);
PendingIntent senderstop = PendingIntent.getBroadcast(this,
1234567, intentstop, 0);
AlarmManager alarmManagerstop = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManagerstop.cancel(senderstop);
关于android - 停止Android alarmmanager的setrepeat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6389143/