停止的Andr​​oid alarmmanager的setrepeat [英] Stop the setrepeat of Android alarmmanager

查看:227
本文介绍了停止的Andr​​oid alarmmanager的setrepeat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了警报,如下图所示。

I have created the alarm as shown below

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方法,我写了下面的code

I created a button to stop the alarm. In the onclick method i have written the following code

Intent intentstop = new Intent(this, Areceiver.class);
PendingIntent senderstop = PendingIntent.getBroadcast(this,
            0, intentstop, 0);
AlarmManager alarmManagerstop = (AlarmManager) getSystemService(ALARM_SERVICE);

alarmManagerstop.cancel(senderstop);

但作业不会停止。可能是什么问题?

But the job is not stopping. What might be the issue?

推荐答案

您给您的待定意图REQUEST_ code = 1234567,当您启动报警。但是,您使用的是0,当您试图阻止它。试图阻止,并应工作时,使用此

You gave your Pending intent a request_code = 1234567 when you start the alarm. But you are using 0 when you try to stop it. Use this when trying to stop and should work

Intent intentstop = new Intent(this, Areceiver.class);
PendingIntent senderstop = PendingIntent.getBroadcast(this,
            1234567, intentstop, 0);
AlarmManager alarmManagerstop = (AlarmManager) getSystemService(ALARM_SERVICE);

alarmManagerstop.cancel(senderstop);

这篇关于停止的Andr​​oid alarmmanager的setrepeat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆