title: React-Native Android ReactContext returning null
body: <p>As the React-Native <code>AppState</code> API is iOS only I'm writing an appState event emitter for the Android side of my app. In the app's <code>MainActivity</code> on the Java side, I want to emit from the <code>onResume</code> and <code>onPause</code> functions to tell the JS side over the bridge that my app is either in the <strong>foreground</strong> or <strong>background</strong></p>
  
  <p>At the moment, I can minimise my app (and go back to the home-screen on my device) and the <strong>background</strong> event is emitted correctly. However, when I resume my app nothing is fired...also nothing is fired when the app initially opens up. </p>
  
  <p>I've narrowed this down to the fact that in these cases <code>mReactInstanceManager.getCurrentReactContext()</code> is null...for some reason.</p>
  
  <p>Here's my code from <code>MainActivity.java</code>:</p>
  
  <pre><code>@Override
  protected void onPause() {
      super.onPause();
  
      if (mReactInstanceManager != null) {
          mReactInstanceManager.onPause();
  
          //send the appState back to JS
          Log.d("REACT_STATE", "Paused");  //this always fires
          if(mReactInstanceManager.getCurrentReactContext()!=null) {
              WritableMap params = Arguments.createMap();
              params.putString("currentAppState", "background");
              sendEvent(mReactInstanceManager.getCurrentReactContext(), "appStateChange", params);
          }
      }
  }
  </code></pre>
  
  <p>and,</p>
  
  <pre><code>@Override
  protected void onResume() {
      super.onResume();
  
      if (mReactInstanceManager != null) {
          mReactInstanceManager.onResume(this, this);
  
          //send the appState back to JS
          Log.d("REACT_STATE", "Resumed"); //this also always fires
          if(mReactInstanceManager.getCurrentReactContext()!=null) {
              WritableMap params = Arguments.createMap();
              params.putString("currentAppState", "foreground");
              sendEvent(mReactInstanceManager.getCurrentReactContext(), "appStateChange", params);
          }
      }
  }
  </code></pre>
  
  <p>and this is the emitter code:</p>
  
  <pre><code>private void sendEvent(ReactContext reactContext,
                         String eventName,
                         @Nullable WritableMap params) {
      reactContext
              .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
              .emit(eventName, params);
  }
  </code></pre>
  
  <p>The JS side of things is set up OK and working - I can provide this code if it helps. I'm fairly certain my issue lies on this side. Am I trying to emit this at the wrong time? Do I need to move it elsewhere? Any advice is much appreciated! </p>