@@ -80,8 +80,6 @@ public class RNOneSignal extends NativeOneSignalSpec
8080 INotificationLifecycleListener {
8181 public static final String NAME = "OneSignal" ;
8282
83- private ReactApplicationContext mReactApplicationContext ;
84-
8583 private boolean oneSignalInitDone ;
8684 private boolean hasSetPermissionObserver = false ;
8785 private boolean hasSetPushSubscriptionObserver = false ;
@@ -194,8 +192,7 @@ private void removeObservers() {
194192
195193 public RNOneSignal (ReactApplicationContext reactContext ) {
196194 super (reactContext );
197- mReactApplicationContext = reactContext ;
198- mReactApplicationContext .addLifecycleEventListener (this );
195+ reactContext .addLifecycleEventListener (this );
199196 notificationWillDisplayCache = new HashMap <String , INotificationWillDisplayEvent >();
200197 preventDefaultCache = new HashMap <String , INotificationWillDisplayEvent >();
201198
@@ -229,7 +226,6 @@ public void onCatalystInstanceDestroy() {
229226
230227 @ Override
231228 public void initialize (String appId ) {
232- Context context = mReactApplicationContext .getCurrentActivity ();
233229 OneSignalWrapper .setSdkType ("reactnative" );
234230 OneSignalWrapper .setSdkVersion ("050213" );
235231
@@ -238,10 +234,10 @@ public void initialize(String appId) {
238234 return ;
239235 }
240236
237+ ReactApplicationContext reactContext = getReactApplicationContext ();
238+ Context context = reactContext .getCurrentActivity ();
241239 if (context == null ) {
242- // in some cases, especially when react-native-navigation is installed,
243- // the activity can be null, so we can initialize with the context instead
244- context = mReactApplicationContext .getApplicationContext ();
240+ context = reactContext .getApplicationContext ();
245241 }
246242
247243 OneSignal .initWithContext (context , appId );
@@ -362,7 +358,7 @@ public void onWillDisplay(INotificationWillDisplayEvent event) {
362358
363359 INotification notification = event .getNotification ();
364360 String notificationId = notification .getNotificationId ();
365- notificationWillDisplayCache .put (notificationId , ( INotificationWillDisplayEvent ) event );
361+ notificationWillDisplayCache .put (notificationId , event );
366362 event .preventDefault ();
367363
368364 try {
@@ -686,19 +682,21 @@ public void removeAliases(ReadableArray aliasLabels) {
686682 @ Override
687683 public void getOnesignalId (Promise promise ) {
688684 String onesignalId = OneSignal .getUser ().getOnesignalId ();
689- if (onesignalId .isEmpty ()) {
690- onesignalId = null ;
685+ if (onesignalId == null || onesignalId .isEmpty ()) {
686+ promise .resolve (null );
687+ } else {
688+ promise .resolve (onesignalId );
691689 }
692- promise .resolve (onesignalId );
693690 }
694691
695692 @ Override
696693 public void getExternalId (Promise promise ) {
697694 String externalId = OneSignal .getUser ().getExternalId ();
698- if (externalId .isEmpty ()) {
699- externalId = null ;
695+ if (externalId == null || externalId .isEmpty ()) {
696+ promise .resolve (null );
697+ } else {
698+ promise .resolve (externalId );
700699 }
701- promise .resolve (externalId );
702700 }
703701
704702 @ Override
0 commit comments