PendinIntent
및 AlarmManager
을 사용하여 일정 기간 후에 다른 활동을 시작하는 서비스가 있습니다. 서비스가 나는 또한 활동을 원치 않는 사용자 넣다 서비스를 취소 할 수있는 버튼이있는 알림을 설정 시작되면AlarmManager가 관련 서비스를 취소 한 후에도 여전히 알람을 발생시키고 PendingIntent
Calendar cal = Calendar.getInstance(); //Create a calendar
cal.add(Calendar.MINUTE, 1); //Add the set minutes to the alarm
Intent dialogIntent = new Intent(this, alarmRingLayout.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1234, dialogIntent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am = (AlarmManager)getSystemService(Activity.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
: 여기
는 서비스의 관련 코드 쏘다. "취소"버튼을 클릭에 는stopService()
가 호출됩니다 :
stopService(new Intent(StopPowerNapAlarmService.this, PowerNapAlarmService.class));
onDestroy()
는 통지를 취소하고 취소 stopSelf()
그것은 또한 시도 호출을 통해 다음과 같은 코드를 가지고 PendingIntent
및 AlarmManager
.
문제는 onDestroy
이 호출 된 후에도 활동이 열리는 문제입니다. PendingIntent
및/또는 AlarmManager
이 취소되지 않는 것으로 보입니다.
@Override
public void onDestroy() {
Toast.makeText(this, "Alarm Finished", Toast.LENGTH_SHORT).show();
CancelNotification(this, 0);
//Cancel the pending intent and AlarmManager
Intent myntent = new Intent(PowerNapAlarmService.this, PowerNapAlarmService.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this,
1234, myntent, PendingIntent.FLAG_UPDATE_CURRENT);
pendingIntent.cancel();
AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
am.cancel(pendingIntent);
stopSelf();
}
잘못 이상 무슨 것입니다 : 여기
는onDestroy()
코드입니다?