2014-09-19 3 views
0

Как удалить все AlarmManager в android. Я вижу ответ вроде «Просто определите новый PendingIntent, как именно тот, который вы определили при его создании». , но я не сделал такой же ожидающий запрос, потому что в requestCode я использую System.currentTimeMillis(). Помоги мне, пожалуйста!Как удалить все AlarmManager android

Intent intent = new Intent(this, ShowNotificationService.class); 
PendingIntent pIntent = PendingIntent.getService(this, (int) System.currentTimeMillis(), intent, 0); 
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); 
manager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pIntent); 
+1

'но я не сделал то же pendingIntent, потому что в requestCode я использую System.currentTimeMillis()' не используйте 'System.currentTimeMillis()' ... – njzk2

+0

я исправить код, увидеть снова, пожалуйста, – bvv

ответ

1

Я нахожу, как исправить это! Я пишу System.currentTimeMillis() в Set в SharedPrefences, и перед установкой нового Alarm i delete old Alarm!

Set<String> unicTimesSet = sp.getStringSet(cons.UNIC_TIMES_SET, new HashSet<String>()); 
    for (String unicTime : unicTimesSet) { 
     Intent intentShowNotif = new Intent(this, ShowNotificationService.class); 
     PendingIntent pIntent = PendingIntent.getService(this, (int)Long.parseLong(unicTime), intentShowNotif, 0); 
     manager.cancel(pIntent); 
    }