2014-09-19 64 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); 
    }