diff --git a/android/app/src/main/java/com/mattermost/rnbeta/CustomPushNotification.java b/android/app/src/main/java/com/mattermost/rnbeta/CustomPushNotification.java index 368daa971..5413c3d6b 100644 --- a/android/app/src/main/java/com/mattermost/rnbeta/CustomPushNotification.java +++ b/android/app/src/main/java/com/mattermost/rnbeta/CustomPushNotification.java @@ -17,7 +17,9 @@ import android.app.Notification; import android.app.NotificationManager; import android.app.RemoteInput; import java.util.LinkedHashMap; +import java.util.Collections; import java.util.ArrayList; +import java.util.List; import java.lang.reflect.Field; import com.wix.reactnativenotifications.core.notification.PushNotification; @@ -40,7 +42,7 @@ public class CustomPushNotification extends PushNotification { public static final String NOTIFICATION_REPLIED_EVENT_NAME = "notificationReplied"; private static LinkedHashMap channelIdToNotificationCount = new LinkedHashMap(); - private static LinkedHashMap> channelIdToNotification = new LinkedHashMap>(); + private static LinkedHashMap> channelIdToNotification = new LinkedHashMap>(); private static AppLifecycleFacade lifecycleFacade; private static Context context; @@ -74,14 +76,16 @@ public class CustomPushNotification extends PushNotification { channelIdToNotificationCount.put(channelId, count); Object bundleArray = channelIdToNotification.get(channelId); - ArrayList list = null; + List list = null; if (bundleArray == null) { - list = new ArrayList(0); + list = Collections.synchronizedList(new ArrayList(0)); } else { - list = (ArrayList)bundleArray; + list = Collections.synchronizedList((List)bundleArray); + } + synchronized (list) { + list.add(0, data); + channelIdToNotification.put(channelId, list); } - list.add(0, data); - channelIdToNotification.put(channelId, list); } if ("clear".equals(type)) { @@ -192,7 +196,7 @@ public class CustomPushNotification extends PushNotification { String summaryTitle = String.format("%s (%d)", title, numMessages); Notification.InboxStyle style = new Notification.InboxStyle(); - ArrayList list = (ArrayList) channelIdToNotification.get(channelId); + List list = new ArrayList(channelIdToNotification.get(channelId)); for (Bundle data : list){ String msg = data.getString("message");