我已经创建了警报,如下所示
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);
但是工作并没有停止。可能是什么问题?
答案 0 :(得分:32)
启动闹钟时,您的待处理意图为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);