如何取消android中的特定警报 [英] How to cancel specific Alarm in android

查看:28
本文介绍了如何取消android中的特定警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,用户可以为同一部电影设置多个闹钟,例如上映日期"、上映前一周"、上映前一个月",现在我被困在取消特定闹钟上,我知道如何使用电影 id 取消警报,但如何使用电影 id 和类型取消警报.将两者连接在一起并将其作为 id 传递给我的待定意图?

In my app, the user can set multiple alarms for the same movie e.g "On release date", "A week before release", "A month before release" and now I'm stuck on cancelling a specific alarm, I know how to cancel an alarm with and movie id, but how to I cancel it with the movie id and the type. do I concatenate both together and pass it as the id to my pending intent?

代码:

    public void cancelAlarm(Context context, _Alarm alarm) {
    //Log.d(TAG, "{cancelAlarm}");
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, AlarmReceiver.class);
    PendingIntent alarmIntent = PendingIntent.getBroadcast(context, (int) alarm.getGameId(), intent, 0);
    alarmManager.cancel(alarmIntent);
}

闹钟类有电影的id和闹钟的类型

Alarm class has the id of the movie and the type of the alarm

推荐答案

我是否将两者连接在一起并将其作为 id 传递给我的待处理意图?

do I concatenate both together and pass it as the id to my pending intent?

这似乎合乎逻辑.

您也可以使用以下方式来了解您的 PendingIntent 是否存在.

Also you can use below way to know if your PendingIntent exists.

PendingIntent alarmIntent = PendingIntent.getBroadcast(context, requestCode,
          intent, PendingIntent.FLAG_NO_CREATE);
if (broadcast != null) {
    alarmManager.cancel(alarmIntent );
}

这篇关于如何取消android中的特定警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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