@@ -297,7 +297,7 @@ static Notification scheduleAlarmWithNotification(Context context, Class activit
297
297
// fireTime not taken from notification, because we may have adjusted it
298
298
299
299
Notification notification = buildNotificationForSending (context , activityClass , notificationBuilder );
300
- mScheduledNotifications . put (Integer .valueOf (id ), notification );
300
+ putScheduledNotification (Integer .valueOf (id ), notification );
301
301
intent .putExtra (KEY_NOTIFICATION_ID , id );
302
302
303
303
PendingIntent broadcast = getBroadcastPendingIntent (context , id , intent , PendingIntent .FLAG_UPDATE_CURRENT );
@@ -404,8 +404,10 @@ private static void performNotificationHousekeeping(Context context, Set<String>
404
404
synchronized (UnityNotificationManager .class ) {
405
405
// list might have changed while we searched
406
406
Set <String > currentIds = new HashSet <>(getScheduledNotificationIDs (context ));
407
- for (String id : invalid )
407
+ for (String id : invalid ) {
408
408
currentIds .remove (id );
409
+ removeScheduledNotification (Integer .valueOf (id ));
410
+ }
409
411
saveScheduledNotificationIDs (context , currentIds );
410
412
mSentSinceLastHousekeeping = 0 ;
411
413
}
@@ -665,7 +667,7 @@ public void onReceive(Context context, Intent intent) {
665
667
id = builder .getExtras ().getInt (KEY_NOTIFICATION_ID , -1 );
666
668
notif = buildNotificationForSending (context , openActivity , builder );
667
669
// if notification is not sendable, it wasn't cached
668
- mScheduledNotifications . put (Integer .valueOf (id ), notif );
670
+ putScheduledNotification (Integer .valueOf (id ), notif );
669
671
}
670
672
671
673
if (notif != null ) {
@@ -821,8 +823,7 @@ public static Object getNotificationOrBuilderForIntent(Context context, Intent i
821
823
if (intent .hasExtra (KEY_NOTIFICATION_ID )) {
822
824
int id = intent .getExtras ().getInt (KEY_NOTIFICATION_ID );
823
825
Integer notificationId = Integer .valueOf (id );
824
- if (mScheduledNotifications .containsKey (notificationId )) {
825
- notification = mScheduledNotifications .get (notificationId );
826
+ if ((notification = getScheduledNotification (notificationId )) != null ) {
826
827
sendable = true ;
827
828
} else {
828
829
// in case we don't have cached notification, deserialize from storage
@@ -870,4 +871,16 @@ public void showNotificationSettings(String channelId) {
870
871
settingsIntent .addFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
871
872
mActivity .startActivity (settingsIntent );
872
873
}
874
+
875
+ private static synchronized void putScheduledNotification (Integer id , Notification notification ) {
876
+ mScheduledNotifications .put (id , notification );
877
+ }
878
+
879
+ private static synchronized Notification getScheduledNotification (Integer id ) {
880
+ return mScheduledNotifications .get (id );
881
+ }
882
+
883
+ private static synchronized Notification removeScheduledNotification (Integer id ) {
884
+ return mScheduledNotifications .remove (id );
885
+ }
873
886
}
0 commit comments