如何删除android中的所有AlarmManager。我看到答案就像"只需定义一个新的PendingIntent,就像你在创建它时定义的一样。" ,但我没有使相同的pendingIntent,因为在requestCode
我使用System.currentTimeMillis()。请帮帮我!
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);
答案 0 :(得分:1)
我发现如何解决它!我在SharedPrefences中的Set中编写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);
}