Skip to content

Commit 9a21b05

Browse files
committed
One Random object is enough
1 parent c5e01ed commit 9a21b05

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class UnityNotificationManager extends BroadcastReceiver {
5050
protected Activity mActivity = null;
5151
protected Class mOpenActivity = null;
5252
protected UnityNotificationBackgroundThread mBackgroundThread;
53+
protected Random mRandom;
5354

5455
protected static final String TAG_UNITY = "UnityNotifications";
5556

@@ -81,6 +82,7 @@ public UnityNotificationManager(Context context, Activity activity) {
8182
mContext = context;
8283
mActivity = activity;
8384
mBackgroundThread = new UnityNotificationBackgroundThread();
85+
mRandom = new Random();
8486

8587
try {
8688
ApplicationInfo ai = activity.getPackageManager().getApplicationInfo(activity.getPackageName(), PackageManager.GET_META_DATA);
@@ -303,9 +305,8 @@ public NotificationChannelWrapper[] getNotificationChannels() {
303305

304306
private int generateUniqueId() {
305307
int id = 0;
306-
Random random = new Random();
307308
do {
308-
id += random.nextInt(1000);
309+
id += mRandom.nextInt(1000);
309310
} while (mScheduledNotifications.containsKey(Integer.valueOf(id)));
310311

311312
return id;

0 commit comments

Comments
 (0)