2017-04-08 5 views
0

트리거에서 Activity 노트를 만듭니다! 그리고 Alarm3Alarm 생성하는 경우 Alarm 의미 만 마지막 트리거 삭제, 다른 Activity 코드를 삭제하고 나는 Alarm1가 삭제를 삭제하고 싶지만 Alarm1의 시간에 도달하면 그것은 이미 삭제하는 동안 트리거 및 Alarm2 및 3 정적 브로드 캐스트 ID에서만 알람 예를 들어 알람이 마지막으로 울림 트리거가 다른 활동에서 코드 삭제 다른 활동에서 동일한 보류 의도를 사용하여 삭제하는 경우 어떻게 보류중인 의도를 사용할 수 있습니까? 내 삭제 경보 activit에서 트리거 경보를 사용하는 y다른 활동을 사용하여 여러 알람을 취소하는 방법

AlarmManager alarmMgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE); 
        Intent intent = new Intent(getApplicationContext(), AlarmReceiver.class); 
        String alertTitle = mTitleText.getText().toString(); 
        intent.putExtra(getString(R.string.alert_title), alertTitle); 
        // broadcastCode++; 
        PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), broadcastCode, intent, PendingIntent.FLAG_UPDATE_CURRENT); 
        alarmMgr.set(AlarmManager.RTC_WAKEUP, calender.getTimeInMillis(), pendingIntent); 
        cv.put(mDbHelper.TIME, timeString); 
        cv.put(mDbHelper.DATE, dateString); 
public void delete(int id) 
{ 

    db.delete(DbHelper.TABLE_NAME, DbHelper.C_ID + "="+id, null); 
    db.close(); 

    Intent intent = new Intent(getBaseContext(), AlarmReceiver.class); 
    PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), CreateNote.broadcastCode, intent, 0); 
    AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE); 
    alarmManager.cancel(pendingIntent); 

} 

답변

0

PendingIntent는 AlarmManager를 시작한 시점과 똑같이 만들어야합니다.

알람을 취소하기 위해 PendingIntent를 만들 때 0 대신 PendingIntent.FLAG_UPDATE_CURRENT을 사용하십시오. FLAG_UPDATE_CURRENT가 0이 아닌 134217728 상수와 같습니다.

+0

목록에서 하나의 알람이 생성되었지만 목록에서 여러 개의 알람이 생성 된 경우 총 ** 5 ** 알람이 생성되고 처음으로 생성 된 알람 ** 1 **이 삭제됩니다 알람이 발생하면 시간에 따라 트리거되고 알람 ** 2,3,4,5 **는 트리거되지 않습니다. –

+0

개별 알람은 'REQUEST_CODE'및 'PendingIntent'로 래핑 된 원본'Intent '로 식별됩니다. . 'REQUEST_CODE' (데이터베이스에 저장하는 것처럼 보임)와'Intent'가 알람 설정시 지정한 값과 일치하는지 확인해야합니다. –

+0

당신은 REQUEST_CODE를 말하고 의도는 데이터베이스에 저장해야합니다. –

0

사용이 코드 :이 도움이

PendingIntent pendingIntent = PendingIntent.getBroadcast(this, _id, intent, 0); 
     AlarmManager alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); 
     alarmManager.cancel(pendingIntent); 

희망.

+0

어떤 종류의 이드를 대체합니까 –

+0

알람을 생성하는 데 사용하는 동일한 ID를 사용하고 있습니다. 여러 알람이 작동하지 않는 단일 알람에서 작동합니다. –

+0

Sir Simrantjeet 노래가 부탁드립니다. 약한 –