Skip to content

Commit 423c9b0

Browse files
committed
Make mScheduledNotifications an instance member
1 parent 8701ab8 commit 423c9b0

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

com.unity.mobile.notifications/Runtime/Android/Plugins/com/unity/androidnotifications/UnityNotificationManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@
4242
public class UnityNotificationManager extends BroadcastReceiver {
4343
protected static NotificationCallback mNotificationCallback;
4444
protected static UnityNotificationManager mUnityNotificationManager;
45-
private static ConcurrentHashMap<Integer, Notification.Builder> mScheduledNotifications = new ConcurrentHashMap();
4645

4746
private Context mContext = null;
4847
private Activity mActivity = null;
4948
private Class mOpenActivity = null;
5049
private UnityNotificationBackgroundThread mBackgroundThread;
5150
private Random mRandom;
5251
private HashSet<Integer> mVisibleNotifications;
52+
private ConcurrentHashMap<Integer, Notification.Builder> mScheduledNotifications;
5353

5454
static final String TAG_UNITY = "UnityNotifications";
5555

@@ -74,6 +74,8 @@ private void initialize(Activity activity, NotificationCallback notificationCall
7474
if (mContext == null)
7575
mContext = activity.getApplicationContext();
7676
mActivity = activity;
77+
if (mScheduledNotifications == null)
78+
mScheduledNotifications = new ConcurrentHashMap();
7779
if (mBackgroundThread == null)
7880
mBackgroundThread = new UnityNotificationBackgroundThread(this, mScheduledNotifications);
7981
if (mRandom == null)
@@ -114,6 +116,7 @@ static synchronized UnityNotificationManager getNotificationManagerImpl(Context
114116
mUnityNotificationManager = new UnityNotificationManager();
115117
mUnityNotificationManager.mContext = context.getApplicationContext();
116118
mUnityNotificationManager.mVisibleNotifications = new HashSet<>();
119+
mUnityNotificationManager.mScheduledNotifications = new ConcurrentHashMap();
117120
}
118121

119122
return mUnityNotificationManager;

com.unity.mobile.notifications/Tests/Runtime/Android/AndroidNotificationSendingTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,12 @@ public IEnumerator SendNotification_CanReschedule()
347347
yield return new WaitForSeconds(0.2f);
348348

349349
var manager = managerClass.GetStatic<AndroidJavaObject>("mUnityNotificationManager");
350+
// clear cached notifications to not mess up future tests
351+
manager.Get<AndroidJavaObject>("mScheduledNotifications").Call("clear");
350352
// simulate reboot by directly cancelling scheduled alarms preserving saves
351353
manager.Call("cancelPendingNotificationIntent", id);
352354
// temporary null the manager, cause that's what we have in reality
353355
managerClass.SetStatic<AndroidJavaObject>("mUnityNotificationManager", null);
354-
// also clear cached notifications, since they don't exist after reboot
355-
managerClass.GetStatic<AndroidJavaObject>("mScheduledNotifications").Call("clear");
356356

357357
yield return new WaitForSeconds(0.2f);
358358
// simulate reboot by calling reschedule method, that is called after reboot

0 commit comments

Comments
 (0)