@@ -105,34 +105,29 @@ private JSONObject jsonFromErrorMessageString(String errorMessage) throws JSONEx
105105
106106 @ ReactMethod
107107 public void init (String appId ) {
108- Activity activity = mReactApplicationContext .getCurrentActivity ();
108+ Context context = mReactApplicationContext .getCurrentActivity ();
109109
110110 if (oneSignalInitDone ) {
111- Log .w ("onesignal" , "Already initialized the OneSignal React-Native SDK" );
111+ Log .e ("onesignal" , "Already initialized the OneSignal React-Native SDK" );
112112 return ;
113113 }
114114
115115 oneSignalInitDone = true ;
116116
117117 OneSignal .sdkType = "react" ;
118118
119- if (activity == null ) {
119+ if (context == null ) {
120120 // in some cases, especially when react-native-navigation is installed,
121121 // the activity can be null, so we can initialize with the context instead
122- OneSignal .init (mReactApplicationContext .getApplicationContext (),
123- null ,
124- appId ,
125- new NotificationOpenedHandler (mReactContext ),
126- new NotificationReceivedHandler (mReactContext )
127- );
128- } else {
129- OneSignal .init (activity ,
130- null ,
131- appId ,
132- new NotificationOpenedHandler (mReactContext ),
133- new NotificationReceivedHandler (mReactContext )
134- );
122+ context = mReactApplicationContext .getApplicationContext ();
135123 }
124+
125+ OneSignal .init (context ,
126+ null ,
127+ appId ,
128+ new NotificationOpenedHandler (mReactContext ),
129+ new NotificationReceivedHandler (mReactContext )
130+ );
136131 }
137132
138133 @ ReactMethod
0 commit comments