title: How to send event from MainActivity onCreate to React Native?
body: <p>I'm working on an alarm clock and I can't figure out how to sendEvent to React Native from MainActivity. This is what I managed to do so far:</p>
  
  <pre><code>    @Override
      protected void onCreate(Bundle savedInstanceState) {
          mInitialProps = new Bundle();
          final Bundle bundle = mActivity.getIntent().getExtras();      
          ReactInstanceManager mReactInstanceManager = getReactNativeHost().getReactInstanceManager();
          ReactApplicationContext context = (ReactApplicationContext) mReactInstanceManager.getCurrentReactContext();    
          if (context == null) {
              mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
                  public void onReactContextInitialized(ReactContext context) {
                      if (bundle != null &amp;&amp; bundle.containsKey("sendAlarm")) {
                          if (bundle.getString("sendAlarm").equals("sendAlarmOn")) {
                              LauncherModule.startAlarm(mActivity); // works 
                              LauncherModule.sendAlarmEvent(); // doesn't work. Should run after alarm manager starts app which previously had been killed
                          }
                      }                                
                  }
              });
          } else {
              if (bundle != null &amp;&amp; bundle.containsKey("sendAlarm")) {
                  if (bundle.getString("sendAlarm").equals("sendAlarmOn")) {
                      LauncherModule.startAlarm(mActivity); // works
                      LauncherModule.sendAlarmEvent(); // works and sends event only when app was left open
                  }
              }                  
          }
          super.onCreate(savedInstanceState);
      }
  </code></pre>
  
  <p>The code works only If app is left open and alarm manager restarts app itself. If I close the app and alarm manager starts it then it seems that only <code>startAlarm</code> function (it has sound effect) is beeing triggered..</p>
  
  <p>No matter what I do whether I put sendEvent function inside Mainactivity or elsewhere (e.g. external module) it simply won't send event if I close the app. I also tried <code>getReactInstanceManager().getCurrentReactContext()</code> combined with <code>while</code> from this question <a href="https://stackoverflow.com/questions/48445010/send-data-from-android-activity-to-react-native">Send data from Android activity to React Native</a> to no avail. </p>
  
  <p>Also tried to create bolean beeing set to true onCreate and then send event onStart or onRestart. Also to no avail.</p>
  
  <p>Any suggestions?</p>
  
  <p>EDIT: Here is how sendEvent function looks like:</p>
  
  <pre><code>public final void sendEvent(String eventName, boolean isAlarmOn) {  
      getReactInstanceManager().getCurrentReactContext()
          .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
          .emit(eventName, isAlarmOn);
  }
  </code></pre>