Alarm not getting stopped

前端 未结 3 1622
清歌不尽
清歌不尽 2021-01-07 08:58

I am trying to stop the alarm and checking it whether it stopped or not, but it always returns true means alarm is working. I tried to stop the alarm based on the answer in

3条回答
  •  梦毁少年i
    2021-01-07 09:43

    You have to pass different id for set alarm

    PendingIntent.getBroadcast(ctx, id, intent,PendingIntent.FLAG_UPDATE_CURRENT);
    

    For cancel alarm you have pass sameidthat you used for set.

    PendingIntent pendingIntent = PendingIntent.getBroadcast(ctx, id,
            intent, PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarmManager = (AlarmManager) ctx
            .getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);
    

提交回复
热议问题