마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

AlarmManager cancel() 이 작동을 하질 않습니다.

0 추천

제가 현재 AlarmManager를 통해 알람을 작동/취소 하는 기능을 만들고 있는데요.

알람을 동작은 문제없이 작동하는데,

알람을 취소하는 기능이 동작하질 않네요.

 

 

아래 코드가 알람을 작동시키는 코드 이구요.

[알람 작동]

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent intent = new Intent(AlarmActivity.this, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(AlarmActivity.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
setAlarm(pendingIntent);

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, timeHour);
calendar.set(Calendar.MINUTE, timeMinute);
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);

 

그 다음 아래 코드가 알람을 취소 시키는 코드 입니다.

[알람 취소]

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

Intent myIntent = new Intent(AlarmActivity.this, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(AlarmActivity.this, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.cancel(pendingIntent);

 

구글링을 해서 얻은 답변들을 통해 PendingIntent Flag를 바꿔본다던지, requestCode를 동일시 시킨다던지 등등의

여러 시도들을 해보았지만, 해결되지 않아서

여기있는 고수님들의 도움을 얻고자 합니다.

 

badojo (120 포인트) 님이 2017년 1월 26일 질문
badojo님이 2017년 1월 26일 수정

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...