Skip to content

Commit

Permalink
Merge pull request #49 from MindscapeHQ/md/sup-330/fix-null-reference
Browse files Browse the repository at this point in the history
[SUP-330] Guard against accessing null objects
  • Loading branch information
mduncan26 authored Aug 4, 2021
2 parents 4054f33 + a64519f commit 7ec1e5a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ public void initRealUserMonitoringNativeSupport() {
//Cant initialise bridge rum twice
if (realUserMonitoringInitialized) return;

if (reactContext.getCurrentActivity() != null) {
if (reactContext != null && reactContext.getCurrentActivity() != null) {
//Store the current activity to differentiate session changes
currentActivity = new WeakReference<>(reactContext.getCurrentActivity());
//Attach the activity listening logic to the Application
reactContext.getCurrentActivity().getApplication().registerActivityLifecycleCallbacks(this);
} else Log.e("TAG", "This react application has no active activity");
} else Log.e("Raygun", "This react application has no active activity");

realUserMonitoringInitialized = true;
}
Expand Down Expand Up @@ -186,16 +186,21 @@ public void onActivityStarted(Activity activity) {
public void onActivityResumed(Activity activity) {
//If the activity that recently paused is returning to the foreground then the whole
// application has resumed, therefore update the session
if (currentActivity.get() == activity) this.sendJSEvent(ON_SESSION_RESUME, null);

if (currentActivity != null && currentActivity.get() == activity) {
this.sendJSEvent(ON_SESSION_RESUME, null);
}
else {
//If any other activity resumes that means that it is taking over from the current activity
else currentActivity = new WeakReference<>(activity);
currentActivity = new WeakReference<>(activity);
}
}

@Override
public void onActivityPaused(Activity activity) {
//If the current activity is pausing then the session is paused
if (currentActivity.get() == activity) this.sendJSEvent(ON_SESSION_PAUSE, null);
if (currentActivity != null && currentActivity.get() == activity) {
this.sendJSEvent(ON_SESSION_PAUSE, null);
}
}

@Override
Expand All @@ -208,7 +213,7 @@ public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {

@Override
public void onActivityDestroyed(Activity activity) {
if (currentActivity.get() == activity) {
if (currentActivity != null && currentActivity.get() == activity) {
this.sendJSEvent(ON_SESSION_END, null);
currentActivity = null;
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "raygun4reactnative",
"title": "Raygun4reactnative",
"version": "1.1.4",
"version": "1.1.5",
"description": "Raygun React Native SDK",
"main": "dist/index.js",
"typescript": {
Expand Down

0 comments on commit 7ec1e5a

Please sign in to comment.