2014-09-19 78 views
0

如何删除android中的所有AlarmManager。我看到像“只需定义一个新的PendingIntent就像您在创建它时定义的那个一样”。 ,但我没有做相同的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

'但由于requestCode我使用System.currentTimeMillis的(我没有犯同样的PendingIntent)'那么就不要使用'System.currentTimeMillis的()'... – njzk2 2014-09-19 14:19:43

+0

我修复代码,请再次请 – bvv 2014-09-19 14:20:58

回答

1

我找到了解决方法!我在Set SharedPrefences中写入System.currentTimeMillis(),并在设置新的Alarm之前删除旧的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); 
    }