@@ -106,37 +106,33 @@ private JSONObject jsonFromErrorMessageString(String errorMessage) throws JSONEx
106
106
@ ReactMethod
107
107
public void init (String appId ) {
108
108
Activity activity = mReactApplicationContext .getCurrentActivity ();
109
-
110
- if (activity == null ) {
111
- // in some cases, especially with react-native-navigation, it can take a while for the Activity to be created
112
- // if null, we should re-attempt initialization after 50 milliseconds.
113
- final String currentAppId = appId ;
114
- Timer timer = new Timer ();
115
- timer .schedule (new TimerTask () {
116
- @ Override
117
- public void run () {
118
- init (currentAppId );
119
- }
120
- }, 50 );
121
- return ;
122
- }
123
109
124
110
if (oneSignalInitDone ) {
125
- Log .w ("onesignal" , "The OneSignal SDK has already been initialized " );
111
+ Log .w ("onesignal" , "Already initialized the OneSignal React-Native SDK " );
126
112
return ;
127
113
}
128
114
129
115
oneSignalInitDone = true ;
130
-
131
116
132
117
OneSignal .sdkType = "react" ;
133
118
134
- OneSignal .init (activity ,
135
- null ,
136
- appId ,
137
- new NotificationOpenedHandler (mReactContext ),
138
- new NotificationReceivedHandler (mReactContext )
139
- );
119
+ if (activity == null ) {
120
+ // in some cases, especially when react-native-navigation is installed,
121
+ // 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
+ );
135
+ }
140
136
}
141
137
142
138
@ ReactMethod
0 commit comments