// Adapted from
// https://github.com/gijoehosaphat/react-native-keep-screen-on

package com.corbt.keepawake;

import android.app.Activity;
import android.view.WindowManager;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

public class KCKeepAwake extends ReactContextBaseJavaModule {

    public KCKeepAwake(ReactApplicationContext reactContext) {
        super(reactContext);
    }

    @Override
    public String getName() {
        return "KCKeepAwake";
    }

    @ReactMethod
    public void activate() {
        final Activity activity = getCurrentActivity();
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            }
        });
    }

    @ReactMethod
    public void deactivate() {
        final Activity activity = getCurrentActivity();
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                activity.getWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            }
        });
    }
}
@@ -672,32 +672,69 @@
 rentActivity();%0A
+%0A        if (activity != null) %7B%0A    
         activity
@@ -769,32 +769,36 @@
 ) %7B%0A            
+    
 @Override%0A      
@@ -795,32 +795,36 @@
 ide%0A            
+  
+  
 public void run(
@@ -819,32 +819,36 @@
 ic void run() %7B%0A
+    
                 
@@ -930,34 +930,42 @@
 N);%0A            
+  
-%7D%0A
+  %7D%0A    
         %7D);%0A    
@@ -956,24 +956,34 @@
         %7D);%0A
+        %7D%0A
     %7D%0A%0A    @
@@ -1081,16 +1081,53 @@
 vity();%0A
+%0A        if (activity != null) %7B%0A    
         
@@ -1170,32 +1170,36 @@
 ) %7B%0A            
+    
 @Override%0A      
@@ -1196,32 +1196,36 @@
 ide%0A            
+ 
+   
 public void run(
@@ -1220,32 +1220,36 @@
 ic void run() %7B%0A
+    
                 
@@ -1346,34 +1346,42 @@
 N);%0A            
+  
-%7D%0A
+  %7D%0A    
         %7D);%0A    
@@ -1372,19 +1372,29 @@
         %7D);%0A
+        %7D%0A
     %7D%0A%7D

Check is activity is null