@@ -71,18 +71,14 @@ public class UnityNotificationManager extends BroadcastReceiver {
71
71
static final String NOTIFICATION_IDS_SHARED_PREFS = "UNITY_STORED_NOTIFICATION_IDS" ;
72
72
static final String NOTIFICATION_IDS_SHARED_PREFS_KEY = "UNITY_NOTIFICATION_IDS" ;
73
73
74
- // Constructor with zero parameter is necessary for system to call onReceive() callback.
75
- public UnityNotificationManager () {
76
- super ();
77
- }
78
-
79
- // Called from Unity managed code to do initialization.
80
- public UnityNotificationManager (Context context , Activity activity ) {
81
- super ();
82
- mContext = context ;
74
+ private void initialize (Activity activity ) {
75
+ if (mContext == null )
76
+ mContext = activity .getApplicationContext ();
83
77
mActivity = activity ;
84
- mBackgroundThread = new UnityNotificationBackgroundThread (context , mScheduledNotifications );
85
- mRandom = new Random ();
78
+ if (mBackgroundThread == null )
79
+ mBackgroundThread = new UnityNotificationBackgroundThread (mContext , mScheduledNotifications );
80
+ if (mRandom == null )
81
+ mRandom = new Random ();
86
82
87
83
try {
88
84
ApplicationInfo ai = activity .getPackageManager ().getApplicationInfo (activity .getPackageName (), PackageManager .GET_META_DATA );
@@ -91,15 +87,15 @@ public UnityNotificationManager(Context context, Activity activity) {
91
87
Boolean rescheduleOnRestart = bundle .getBoolean ("reschedule_notifications_on_restart" );
92
88
93
89
if (rescheduleOnRestart ) {
94
- ComponentName receiver = new ComponentName (context , UnityNotificationRestartOnBootReceiver .class );
95
- PackageManager pm = context .getPackageManager ();
90
+ ComponentName receiver = new ComponentName (mContext , UnityNotificationRestartOnBootReceiver .class );
91
+ PackageManager pm = mContext .getPackageManager ();
96
92
97
93
pm .setComponentEnabledSetting (receiver ,
98
94
PackageManager .COMPONENT_ENABLED_STATE_ENABLED ,
99
95
PackageManager .DONT_KILL_APP );
100
96
}
101
97
102
- mOpenActivity = UnityNotificationUtilities .getOpenAppActivity (context , false );
98
+ mOpenActivity = UnityNotificationUtilities .getOpenAppActivity (mContext , false );
103
99
if (mOpenActivity == null )
104
100
mOpenActivity = activity .getClass ();
105
101
} catch (PackageManager .NameNotFoundException e ) {
@@ -117,9 +113,11 @@ public static UnityNotificationManager getNotificationManagerImpl(Context contex
117
113
118
114
// Called from managed code.
119
115
public static UnityNotificationManager getNotificationManagerImpl (Context context , Activity activity ) {
120
- if (mUnityNotificationManager == null )
121
- mUnityNotificationManager = new UnityNotificationManager (context , activity );
116
+ if (mUnityNotificationManager == null ) {
117
+ mUnityNotificationManager = new UnityNotificationManager ();
118
+ }
122
119
120
+ mUnityNotificationManager .initialize (activity );
123
121
return mUnityNotificationManager ;
124
122
}
125
123
0 commit comments