Skip to content

Commit 765860c

Browse files
committed
Make mNotificationCallback an instance variable
1 parent 423c9b0 commit 765860c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import com.unity3d.player.UnityPlayer;
4141

4242
public class UnityNotificationManager extends BroadcastReceiver {
43-
protected static NotificationCallback mNotificationCallback;
4443
protected static UnityNotificationManager mUnityNotificationManager;
4544

4645
private Context mContext = null;
@@ -50,6 +49,7 @@ public class UnityNotificationManager extends BroadcastReceiver {
5049
private Random mRandom;
5150
private HashSet<Integer> mVisibleNotifications;
5251
private ConcurrentHashMap<Integer, Notification.Builder> mScheduledNotifications;
52+
private NotificationCallback mNotificationCallback;
5353

5454
static final String TAG_UNITY = "UnityNotifications";
5555

@@ -74,6 +74,7 @@ private void initialize(Activity activity, NotificationCallback notificationCall
7474
if (mContext == null)
7575
mContext = activity.getApplicationContext();
7676
mActivity = activity;
77+
mNotificationCallback = notificationCallback;
7778
if (mScheduledNotifications == null)
7879
mScheduledNotifications = new ConcurrentHashMap();
7980
if (mBackgroundThread == null)
@@ -82,7 +83,6 @@ private void initialize(Activity activity, NotificationCallback notificationCall
8283
mRandom = new Random();
8384
if (mVisibleNotifications == null)
8485
mVisibleNotifications = new HashSet<>();
85-
mNotificationCallback = notificationCallback;
8686

8787
try {
8888
ApplicationInfo ai = activity.getPackageManager().getApplicationInfo(activity.getPackageName(), PackageManager.GET_META_DATA);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,10 @@ public IEnumerator SendNotification_CanReschedule()
358358
// simulate reboot by calling reschedule method, that is called after reboot
359359
rebootClass.CallStatic("rescheduleSavedNotifications", context);
360360

361+
var newManager = managerClass.GetStatic<AndroidJavaObject>("mUnityNotificationManager");
362+
// new manager was supposed to be created, assign callback from original one to get notifications
363+
newManager.Set("mNotificationCallback", manager.Get<AndroidJavaObject>("mNotificationCallback"));
364+
361365
yield return WaitForNotification(120.0f);
362366

363367
Debug.LogWarning("SendNotification_CanReschedule completed");

0 commit comments

Comments
 (0)