@@ -126,12 +126,12 @@ public void initRealUserMonitoringNativeSupport() {
126126 //Cant initialise bridge rum twice
127127 if (realUserMonitoringInitialized ) return ;
128128
129- if (reactContext .getCurrentActivity () != null ) {
129+ if (reactContext != null && reactContext .getCurrentActivity () != null ) {
130130 //Store the current activity to differentiate session changes
131131 currentActivity = new WeakReference <>(reactContext .getCurrentActivity ());
132132 //Attach the activity listening logic to the Application
133133 reactContext .getCurrentActivity ().getApplication ().registerActivityLifecycleCallbacks (this );
134- } else Log .e ("TAG " , "This react application has no active activity" );
134+ } else Log .e ("Raygun " , "This react application has no active activity" );
135135
136136 realUserMonitoringInitialized = true ;
137137 }
@@ -186,16 +186,21 @@ public void onActivityStarted(Activity activity) {
186186 public void onActivityResumed (Activity activity ) {
187187 //If the activity that recently paused is returning to the foreground then the whole
188188 // application has resumed, therefore update the session
189- if (currentActivity .get () == activity ) this .sendJSEvent (ON_SESSION_RESUME , null );
190-
189+ if (currentActivity != null && currentActivity .get () == activity ) {
190+ this .sendJSEvent (ON_SESSION_RESUME , null );
191+ }
192+ else {
191193 //If any other activity resumes that means that it is taking over from the current activity
192- else currentActivity = new WeakReference <>(activity );
194+ currentActivity = new WeakReference <>(activity );
195+ }
193196 }
194197
195198 @ Override
196199 public void onActivityPaused (Activity activity ) {
197200 //If the current activity is pausing then the session is paused
198- if (currentActivity .get () == activity ) this .sendJSEvent (ON_SESSION_PAUSE , null );
201+ if (currentActivity != null && currentActivity .get () == activity ) {
202+ this .sendJSEvent (ON_SESSION_PAUSE , null );
203+ }
199204 }
200205
201206 @ Override
@@ -208,7 +213,7 @@ public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
208213
209214 @ Override
210215 public void onActivityDestroyed (Activity activity ) {
211- if (currentActivity .get () == activity ) {
216+ if (currentActivity != null && currentActivity .get () == activity ) {
212217 this .sendJSEvent (ON_SESSION_END , null );
213218 currentActivity = null ;
214219 }
0 commit comments